Feature/Hotkeys
See original GitHub issueNot sure what interface I want hotkeys to take.
keyboard is a project that offers cross-platform hotkeys and keyboard actions.
Not sure if to model after keyboard
or do something else.
Here’s a quick mockup I have in mind
myhotkey = Hotkey('CTRL+T', some_script)
myhotkey.start() # start the process with the hotkey trigger (e.g. listening in the background)
myhotkey.stop() # stop the script
Where some_script
would be an ahk script to put under the hotkey declaration.
Another possible idea would be to have hotkeys have the ability to perform callbacks for Python functions, similar to keyboard
, but I can’t think of a great way to accomplish this at the moment.
Issue Analytics
- State:
- Created 5 years ago
- Comments:30 (19 by maintainers)
Top Results From Across the Web
Keyboard shortcuts in Windows - Microsoft Support
Learn how to navigate Windows using keyboard shortcuts. Explore a full list of taskbar, command prompt, and general Windows shortcuts.
Read more >Special keys, Keyboard shortcuts, Function keys and Hotkeys
Hotkeys are combinations of keys that when pressed at the same time let you quickly access/open menus using only your keyboard. A hotkey...
Read more >Hotkey Features Integration (Version 9) for Windows 11, 10 ...
This software enables F1-F12 special keys and buttons on your computer.
Read more >Hotkeys (mouse, joystick and keyboard shortcuts) - AutoHotkey
Learn details about hotkeys in general, modifier symbols, context-sensitive hotkeys, custom combinations, mouse wheel hotkeys, function hotkeys, etc.
Read more >Keyboard Shortcuts - Millersville University
To enable your Function keys, check the option not to display this message again. Standard Toolbar Buttons. Button. Keyboard. Shortcut Description. Button.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@Maracko there are some improvements on the way that may help your use case. But let me try to answer your questions:
This library uses finalizer hooks to ensure the AHK process (like those started for hotkeys) is closed. However, as mentioned in the official docs using
os._exit
will not allow cleanup handlers to run. As such, the hotkey process may be left running.So, in short, if your python script exits normally (even with an exception), there shouldn’t be anything you need to do to ensure the ahk executable terminates.
There are, however, cases where cleanup might not run, such as when a Python fatal internal error is detected, or when
os._exit()
is called.In your example, changing
os._exit(1)
tosys.exit(1)
should ensure the AHK process is closed.I’m 100% sure what you mean here.
For Hotkeys, the main Python script must continue to run for the hotkey to continue running. If your app consists only of the AHK hotkey, then you can do something like this:
There are a few improvements on the way that may help your situation:
as mentioned earlier Python callbacks for hotkeys are going to implemented in the near future. So something like
if ahk.key_state("Control") and ahk.key_state("Shift") and ahk.key_state("1")
could reasonably be re-written as a hotkey.There is a daemon feature coming in #111 that will offer greatly improved performance. Currently, each AHK command runs in its own process. The daemon feature will allow AHK commands to be executed in a single long-running AHK process, which should improve efficiency by an order of magnitude, especially for scripts that call methods in rapid succession.
Lastly, I may add a
wait_forever
method to hotkeys… but it will likely just be something simple, like thewhile
loop I wrote above.Hope that answers your question. Let me know if you still have other questions or always feel free to open another issue.
Since we already have the python keyboard project for creating powerful hotkeys from scratch, maybe a useful goal for this project is to incorporate hotkey functionality in a way that makes it as easy as possible to port existing autohotkey hotkeys to this framework.