Re: Simulate Keyboard keypress Delay

2013-02-14 Thread inq1ltd
On Wednesday, February 13, 2013 11:47:36 AM DaGeek247 wrote:
 I am using the windows api feature getasynckeystate() to check the status of
 every key pressed; like this;
 
 #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;
 
 #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;
 
 #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 keypresses, and missing
 others. Does anybody have any suggestions?


this will only work on a windows machine. It is from C++ runtime lib 
msvcrt.dll


in py module 
import msvcrt

while 1:
ch = msvcrt.getch()   ## returns one char
if ch == 'Y' :
   # do stuff or break
break

print %d (%r)  % (ch, ch)


  # also,  kbhit()  #  returns true if char is available

  # also, ungetch(ch)  # undo char ch

jd
inqvista.com






-- 
http://mail.python.org/mailman/listinfo/python-list


Simulate Keyboard keypress Delay

2013-02-13 Thread DaGeek247
I am using the windows api feature getasynckeystate() to check the status of 
every key pressed; like this;

#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;

#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;

#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 keypresses, and missing 
others. Does anybody have any suggestions?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Simulate Keyboard keypress Delay

2013-02-13 Thread 88888 Dihedral
DaGeek247於 2013年2月14日星期四UTC+8上午3時47分36秒寫道:
 I am using the windows api feature getasynckeystate() to check the status of 
 every key pressed; like this;
 
 
 
 #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;
 
 
 
 #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;
 
 
 
 #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 keypresses, and missing 
 others. Does anybody have any suggestions?

I believe you can use the raw_input function in python.

But loop through strings ended by \r\n or \r.
-- 
http://mail.python.org/mailman/listinfo/python-list