Closed goudekid closed 2 years ago
If you're running the raw python you can hack it in like so.
pip install keyboard
Add these imports to top of file
import keyboard
import time
import threading
Amend the run function like so
# There's probably better input catching methods, but this doesn't require TK window focus
def _check_esc_pressed(self):
while True:
if win32gui.GetWindowText(win32gui.GetForegroundWindow()) == "Path of Exile":
if keyboard.is_pressed('esc'):
self._hide(None)
# For chorded inputs you can do this:
# if keyboard.is_pressed('alt') and keyboard.is_pressed('`'):
if keyboard.is_pressed('`'): # My poe keybind
self._scan(None)
time.sleep(0.1) # seconds
def run(self) -> None:
# Run the keyboard check loop in a different thread
kb_input_thread = threading.Thread(target=self._check_esc_pressed)
kb_input_thread.daemon = True
kb_input_thread.start()
self._root.mainloop()
Still tinkering and I'm unfamiliar with TK so this might not be the best solution, there's input libraries like pynput
to consider
My only concern is that in order for this tool to get keyboard events, while running in the background, you'll have to add some global hooks. This may interfere with other programs and cause antivirus to freak out.
The benefit would be using the same key as Poe archenemy inventory to auto trigger the overlay.
Another possible method to investigate, using the 'keyboard' module, works unfocused, easy keybind delcarations (and so can be set by the user in the ui with strings) and if it relies on icky never-ending loops it at least does it under the hood where you don't have to see them :) https://old.reddit.com/r/learnpython/comments/8kh9tb/any_way_to_send_a_keyboardinterrupt_to_an/dz7um52/
Added support for key bindings here: 092a809. You can now also run the tool in non overlay mode (recipes, highlights and tree will still show on top of everything).
Would appreciate if someone could test it before releasing it.
I should mention, that the default behaviour of the tool didn't change. If you don't specify a key binding, then the tool won't call any API related to keyboard events. Hopefully, this should avoid any additional interference with other tools/antiviruses.
Added to v0.2.0 release. Closing.
Mouse bad, keyboard good unga bunga