
February 13th, 2013, 01:59 PM
|
|
Registered User
|
|
Join Date: Feb 2013
Location: The Aether
Posts: 3
Time spent in forums: 44 m 3 sec
Reputation Power: 0
|
|
|
Keyboard Keypress Record Help
I am using the windows api feature getasynckeystate() to check the status of every key pressed; like this;
Code:
#always checking
while(True):
#iterate through list of ascii codes
for num in range(0,127):
#if ascii code key is being pressed
if win32api.GetAsyncKeyState(num):
#do stuff
This works great, almost. The issue that comes up now is that every time i press a key, the code grabs two or three key presses.
So i tried making sure that repeated keys weren't pressed repeatedly;
Code:
#always checking
while(True):
#iterate through list of ascii codes
for num in range(0,127):
#if ascii code key is being pressed
if win32api.GetAsyncKeyState(num):
if oldkeychar == num:
#don't do stuff
else:
#do stuff
this works great, but It won't record stuff like 'look' or 'suffer' because it doesn't record repeated keys. So I try doing a delay instead;
Code:
#always checking
while(True):
#iterate through list of ascii codes
for num in range(0,127):
#if ascii code key is being pressed
if win32api.GetAsyncKeyState(num):
if oldkeychar == num:
if crrenttime > (time.time() - .5)
#do stuff because key has been repeated, but not because it was held down
else:
#don't do stuff because key is pressed to soon
else:
#do stuff because key is not repeated
currenttime = time.time()
this almost works, but I end recording some double key presses, and missing others. Does anybody have any suggestions? Any and all help is greatly appreciated.
|