I'm trying to do some python, the idea is that when a special key on the keyboard is pressed in this case $ and * it will make a web request to my server.
It works but only once, so if I type for example $ it will send the request, but if I type this again or * it doesn't work. So I think it's because it's breaking the loop because of the keyboard.is_pressed() and I don't know how to fix that
Here's the code:
import http.client
import keyboard
while True:
if keyboard.is_pressed('*'):
conn = http.client.HTTPConnection('server_ip:server_port')
payload = "{\n\t\"value\" : 0\n}"
headers = {'Content-Type': "application/json",'Accept': "application/json"}
conn.request("POST", "/api", payload, headers)
res = conn.getresponse()
data = res.read()
elif keyboard.is_pressed('$'):
conn = http.client.HTTPConnection('server_ip:server_port')
payload = "{\n\t\"value\" : 1\n}"
headers = {'Content-Type': "application/json",'Accept': "application/json"}
conn.request("POST", "/api", payload, headers)
res = conn.getresponse()
data = res.read()