toprekt2 / autokey

Automatically exported from code.google.com/p/autokey
GNU General Public License v3.0
0 stars 0 forks source link

Keyboard.press_key() doesn't work until you manually press a key #122

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1.Create a new 1 lined script 
keyboard.press_key("a")
2. Open gEdit and press the hotkey for your script 
3.Nothing will happen until you press another key or click the mouse. 
For example
I'll have gedit open, press Super+F5, and nothing will happen. I'll then type 
the letter s. I'll then see saaaaaaaaaaa... with a repeating until I hit 
another key, d for example. I'll end up with the final output of 
saaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaad

I should just get just get aaaaaaaaaaaaaaaaaaaaa... until I hit and release the 
letter a.

What version of the product are you using? On what operating system?
Version 0.71.2
Using KDE Development Platform 4.6.2 (4.6.2)
Ubuntu 11.04
Please provide any additional information below.

In a separate but perhaps related problem, the press shift, mouse click, 
release shift didn't seem to work properly.

keyboard.press_key("<shift>")
mouse.click_absolute(690,908,1)
keyboard.release_key("<shift>")

Using gimp this code worked as expected. How ever, it did not work in an 
application using wine. It wouldn't register the shift click, only the mouse 
click. 

Original issue reported on code.google.com by deskgl...@gmail.com on 10 Jun 2011 at 1:15

GoogleCodeExporter commented 8 years ago
I'm afraid these are bugs with X event handling and there's nothing I can do 
about either of them.

Original comment by cdekter on 10 Jun 2011 at 2:25

GoogleCodeExporter commented 8 years ago
[deleted comment]
GoogleCodeExporter commented 8 years ago
I encountered the same problem but turns out there is no bug here - it works 
but too fast. So to make this actually work I had to add sleep(some_short_time) 
after press_key() and before release_key(). For example this code works for me:

from time import sleep
wait = 0.2
keyboard.press_key("<alt>")
sleep(wait)
mouse.click_relative_self(0, 0, 1)
sleep(wait)
keyboard.release_key("<alt>")

By the way, I have to use sleep very often in my scripts, otherwise many things 
will not work as expected. I think this worth adding to the autokey FAQ - if 
something does not work as expected then try to add sleep.

Original comment by resea...@science.su on 5 Jan 2014 at 12:44