Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

To send key press or release event to a ahk window? #326

Open
1 task done
vfptr opened this issue Jul 1, 2024 · 1 comment
Open
1 task done

To send key press or release event to a ahk window? #326

vfptr opened this issue Jul 1, 2024 · 1 comment
Labels
question Further information is requested

Comments

@vfptr
Copy link

vfptr commented Jul 1, 2024

Checked the documentation

describe your feature request

I want to simulate long press event by sending keys release or press event to a not activated window. I did not find any way to do this in AHK.Window class.

@spyoungtech
Copy link
Owner

spyoungtech commented Jul 2, 2024

The way you do this is through the send method of the Window class. Doing a long press works the same way as described in the docs describing Repeating or Holding Down a Key. (these features also work with ControlSend, which is the underlying functionality of Window.send).

For example, the AutoHotkey documentation provides:

Send {Up down}  ; Presses down the up-arrow key.
Sleep 1000  ; Keeps it down for one second.
Send {Up up}  ; Releases the up-arrow key.

Using the wrapper, the equivalent doing what you want to a window that is not active:

win = ahk.win_get(title='my window')
win.send('{Up down}')
time.sleep(1)
win.send('{Up up}')

Keep in mind, some windows (especially games) may simply not accept input at all while the window is not active.

@spyoungtech spyoungtech added the question Further information is requested label Jul 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants