0

I'm trying to write some code that checks if any keys are pressed while we have a GUI with appJar and it's not focused. So if the "v" key is pressed it will write something to the console while we are focused in the program window, but I want something to be written even if we are not focused on the program window. AppJar does not check if the keys are pressed while focusing on another application, how can I fix it?

My code

import appJar

app = appJar.gui()

def keyPress(key):
    global startStop
    if key == "v":
       print(0)

app.setSize("550x350")
app.setResizable(canResize=False)
app.setBg("white", override=False, tint=False)
app.setTransparency(100)

app.bindKey("v", keyPress)

app.go()
codester_09
  • 5,622
  • 2
  • 5
  • 27
Ale
  • 17
  • 9

1 Answers1

0

You have to use the' keyboard' module to catch the v key event when the window is not focused.

import appJar
import keyboard

app = appJar.gui()

def keyPress(key):
    global startStop
    if key == "v":
       print(0)

app.setSize("550x350")
app.setResizable(canResize=False)
app.setBg("white", override=False, tint=False)
app.setTransparency(100)

# app.bindKey("v", keyPress)
keyboard.add_hotkey("v",keyPress,args=("v",))

app.go()

codester_09
  • 5,622
  • 2
  • 5
  • 27
  • **i get this error (_I use a macbook_):** `ValueError: ("Key 'v' is not mapped to any known key.", ValueError('Unrecognized character: v'))` – Ale Nov 06 '22 at 20:52