Does Time.sleep require integers?

I am writing a macro that clicks on certain spots on the screen when I press a key.

The first time I press a key, everything works fine.
However, any other keystroke results in an error:

time.sleep(0.1) TypeError: an integer is required 

Here is the code:

 import win32api import win32con import time import pythoncom import pyHook import os def Click(x,y): win32api.SetCursorPos((x,y)) win32api.mouse_event(win32con.MOUSEEVENTF_LEFTDOWN,x,y,0,0) win32api.mouse_event(win32con.MOUSEEVENTF_LEFTUP,x,y,0,0) def DeleteRun(event): Click(1250, 741) time.sleep(0.1) Click(649,261) time.sleep(0.1) Click(651, 348) time.sleep(0.1) Click(800, 442) time.sleep(0.1) Click(865, 612) Click(20,20) KeyGrabber = pyHook.HookManager() KeyGrabber.KeyDown = DeleteRun KeyGrabber.HookKeyboard() pythoncom.PumpMessages() 

It seems that the first time the DeleteRun function DeleteRun started by pyHook , time.sleep( ) accepts the floats.
For any function calls, it seems to take only integers.

What causes this?
I canโ€™t wait 5 seconds for the mouse! This should save time!

Specifications:

  • python 2.7.2
  • Windows 7 (32)
+8
python integer time sleep pyhook
source share
2 answers

OK, how about this? Add return True to DeleteRun:

 def DeleteRun(event): Click(1250, 741) time.sleep(0.1) [...] return True 

I must probably admit that it was a little more than google-fu: read the answer to this question .

+5
source share

I'm not sure what happened to Windows this time, but you can try faking high-precision sleep using select () without file descriptors.

-one
source share

All Articles