4rtzel / poe-archnemesis-scanner

Tool for Path of Exile game to automatically scan Archemesis inventory and display related information
Apache License 2.0
64 stars 25 forks source link

Feature Request - Keybinds #14

Closed goudekid closed 2 years ago

goudekid commented 2 years ago

Mouse bad, keyboard good unga bunga

ZKruse commented 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

4rtzel commented 2 years ago

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.

Davst commented 2 years ago

The benefit would be using the same key as Poe archenemy inventory to auto trigger the overlay.

goudekid commented 2 years ago

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/

4rtzel commented 2 years ago

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.

4rtzel commented 2 years ago

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.

4rtzel commented 2 years ago

Added to v0.2.0 release. Closing.