Consider the following code which prints the event type, key, and list of currently pressed keys for a keyboard event.
from pyhooked import Hook, KeyboardEvent
def handle_events(args):
if isinstance(args, KeyboardEvent):
print args.event_type, args.current_key, args.pressed_key
hk = Hook() # make a new instance of PyHooked
hk.handler = handle_events # add a new shortcut ctrl+a, or triggered on mouseover of (300,400)
hk.hook() # hook into the events, and listen to the presses
When a key, 'a' for example, is held down, the output is: key down A ['A'] and it is repeated until the key is released, which then yields a single output of: key up A [] .
Now consider pressing the 'A' and 'S' Keys simultaneously. For the first example, consider holding 'A' first, then 'S', then letting go of 'A', then 'S'. The output is (in order, repeated if dots follow):
key down A ['A']
...
key down S ['A', 'S']
...
key up A['S']
key down S ['S']
...
key up S []
Now consider the case of releasing 'S' first instead. The output is (in order, repeated if dots follow):
key down A ['A']
...
key down S['A', 'S']
...
key up S ['A']
key up A []
Notice that the difference is that the key down event does not repeat for 'A' after 'S' has been released as was the case for 'S' in the first example. This can be generalized for the case when more than two buttons are pressed as well. In every case, if the last button that was pressed is released, the output stops repeating.
This behavior is inconsistent, however I'm not sure what the intended behavior is. Do we define a keyboard event as a triggered event? Then holding a key down should not repeat output. Or do we define it as the state of the key? In that case the output should repeat for the key(s) being held and when one is released the other(s) should continue to repeat.
Do you have thoughts on what should be the proper output?