I wanted to do an action, as soon as my f key is pressed. The problem is that it spams the action.
import win32api
while True:
f_keystate = win32
Because in the while
loop, when the f key is pressed, GetAsyncKeyState
will detect that the f key is always in the pressed state. As a result, the print
statement is called repeatedly.
Try the following code, you will get the result you want:
import win32api
while True:
keystate = win32api.GetAsyncKeyState(0x46)&0x0001
if keystate > 0:
print('F pressed!')