Questions tagged [python-keyboard]

A small Python library to hook global events, register hotkeys, simulate key presses and more.

A small Python library to hook global events, register hotkeys, simulate key presses and more. Available from pypi.org.

38 questions
4
votes
1 answer

How to async handle callback from keyboard hotkeys?

Need to register global hotkeys. For example, f4 and f8. With keyboard library while first callback didn't return, the next won't call. Another words, logs like this pressed f4 end for f4 pressed f8 end for f8 But I want to like this pressed…
Viewed
  • 1,159
  • 3
  • 16
  • 43
2
votes
1 answer

Trying to type '→' with keyboard module

I am making a program that writes a program in TI-Basic. In TI-Basic, to set a variable, the syntax is value → varname. The TI-Connect software doesn't like it when I copy-paste, so I'm using the keyboard module to simulate keypresses. I can't…
dimani128
  • 75
  • 7
2
votes
3 answers

Every "q'" press print something in Python

Once I press "q" it prints this text many times. I want to print it once. import keyboard while True: try: if keyboard.is_pressed("q"): print('q pressed') except: break
2
votes
2 answers

Best way to close the program pressing Esc anytime the user wants?

Which is the best way to close a program anytime by pressing Esc? I need to implement this thing in an important code, but my experiments didn't work. This is the last one: from multiprocessing import Process import keyboard import sys def…
Matt
  • 33
  • 4
1
vote
1 answer

sys.exit function doesn't end the program

there's my code: import sys import keyboard import rotatescreen from time import sleep pd = rotatescreen.get_primary_display() angel = [90, 180, 270, 0] for i in range(2): for x in angel: pd.rotate_to(x) sleep(0.5) if…
FeerQ
  • 11
  • 1
1
vote
1 answer

Using a key listener to stop a loop

I'm trying to make python run a loop and when I press Shift+a the loop stops: import pyautogui import time import random from pynput.mouse import Button, Controller from pynput import keyboard COMBINATIONS =[ {keyboard.Key.shift,…
GamerBOT
  • 13
  • 2
1
vote
1 answer

input() not waiting for user to press enter

I'm trying to make something that lets you input types of food or restaurants and randomly chooses one of them. However, in the function that should let me add food to the list, the input function isn't waiting for anything to be typed in like it…
Evan S
  • 11
  • 3
1
vote
2 answers

How to stop a function & exit program running in a while loop on key press?

I need to stop a program when a keyboard key q is pressed. How can I achieve that in the below code? How can I ignore time.sleep & detect a keypress & exit the program by printing something? Currently, the keypress gets detected only after 10…
user17219216
1
vote
2 answers

keyboard.is_pressed() breaking the loop

I'm trying to do some python, the idea is that when a special key on the keyboard is pressed in this case $ and * it will make a web request to my server. It works but only once, so if I type for example $ it will send the request, but if I type…
Drakeee0909
  • 67
  • 1
  • 8
1
vote
1 answer

How to make the Keyboard module detect if a right click was made

I have tried to search google and other websites such as GitHub but I cant find a way to detect if the right key has been pressed. I am using the two modules Keyboard and Pyautogui to make a auto clicker but all the ideas that I have come up with…
1
vote
0 answers

When I press the delete key in my program , it also clicks the '.' key

So I am making a calculator, I want the user to press the delete key to delete what they had written in the entry field, But When I do it also presses the decimal('.') key in the keyboard, thus activating its own function, I am using the keyboard…
Duffy
  • 123
  • 7
1
vote
1 answer

Making keyboard shortcut, but it does not do anything

I am trying to make a shortcut to open google when I do the function normal it works but when I try to do it in a shortcut it doesn't work. import pyautogui as pg import keyboard hotkey1 = "ctrl+alt+w" def google(): pg.hotkey("win") …
1
vote
2 answers

Keyboard module toggle Listener

I just found out about the pynput library which is exactly what I have been looking for. My goal is to capure the keys the user is typing and whenever a specific sequence of keys was captured I want the computer to write a sequence to the current…
1
vote
0 answers

Pressing F5 (I think other Fs too) doesn't work

The code import time,os, keyboard framedist = 3 #x Seconds, not x milliseconds version = "1.0 prototype" frames=[] def frame(action): print(action) time.sleep(framedist) os.system("cls") def createframe(action): …
C.Flance
  • 17
  • 1
  • 5
1
vote
2 answers

Python Keyboard Module, wait for user

I'm currently building a python code to play Blackjack where I need to be able to call certain functions uppon keypress without necessarily being in the terminal. I found this keyboard module which helped but I came across this issue. def…
Cruxer
  • 21
  • 6
1
2 3