spyoungtech / ahk

Python wrapper for AutoHotkey with full type support. Harness the automation power of AutoHotkey with the beauty of Python.
MIT License
887 stars 66 forks source link

ahk.key_down not working as expected #308

Closed GuilhermeBaldo closed 5 months ago

GuilhermeBaldo commented 6 months ago

describe your issue

When trying to reproduce the example from the README.md of pressing and not releasing a key, and I got an unexpected result.

from ahk import AHK

ahk = AHK()

ahk.key_down('A')  # Press down (but do not release) A key
print(ahk.key_state('A'))
ahk.key_up('A')  # Release the key

The following outputs 0, while I was expecting it to output 1 as A would be pressed. The key A is a placeholder, I tested with several different keys. Am I doing this wrong?

ahk.version

1.7.2

AutoHotkey version

v1

Code to reproduce the issue

from ahk import AHK

ahk = AHK()

ahk.key_down('A')  # Press down (but do not release) A key
print(ahk.key_state('A'))
ahk.key_up('A')  # Release the key

Traceback/Error message

No response

spyoungtech commented 6 months ago

Hmm. When I test this, I get the expected result:

In [1]: from ahk import AHK

In [2]: ahk = AHK()

In [3]: ahk.key_down('A')  # Press down (but do not release) A key
   ...: print(ahk.key_state('A'))
   ...: ahk.key_up('A')  # Release the key
1

In [4]:

I'm not sure what might cause a situation where this prints 0. I don't think the AutoHotkey version should matter, but I tested on 1.1.33.09

GuilhermeBaldo commented 5 months ago

Thanks for the response @spyoungtech! Thats super odd. I will investigate it further, as this is a problem here and not in the tool. I think you can close the issue if you wish.

spyoungtech commented 5 months ago

Sure thing. Feel free to open a new issue any time if you still have questions or can find a way we can reproduce the issue.

One last thought: you may find this comment useful, if it's the case that you are encountering this issue specifically when checking for the key state of a modifier key (like shift, alt, etc.) in close proximity to having AutoHotkey send input.