keyboard-events

change KeyboardInterrupt to 'enter'

change KeyboardInterrupt to 'enter' Question: I have the following code: import time def run_indefinitely(): while True: # code to run indefinitely goes here print("Running indefinitely…") time.sleep(1) try: # Run the code indefinitely until Enter key is pressed run_indefinitely() except KeyboardInterrupt: print("Loop interrupted by user") Is there a way to break out of the while loop …

Total answers: 2

Simple keyboard program with issues

Simple keyboard program with issues Question: This program sometimes counts one key press as 2 presses or as 0,5 press. Program: import keyboard while True: if keyboard.read_key() == ‘h’: print("1") elif keyboard.read_key() == ‘j’: print("2") elif keyboard.read_key() == ‘k’: print("3") I want this program to count 1 key press as one action. I have no …

Total answers: 1

Detect key-presses with Python in macOS

Detect key-presses with Python in macOS Question: I wrote a macro that use key-presses to record. It is using the keyboard module that does not work on macOS. Code import time import keyboard import pyautogui while True: if keyboard.is_pressed(‘e’): #recording v = [0] z = True m = time.time() while z == True: if keyboard.is_pressed(‘space’): …

Total answers: 1

problem rising events with keyboard clicks in PySimpleGUI

problem rising events with keyboard clicks in PySimpleGUI Question: I tried to find codes online about rising events in my PySimpleGUI program by simple keyboard clicks like ENTER or Ctrl+A for instance but I couldn’t just find any about it, I went to the documentation of PySimpleGUI and didn’t shut my tap without learning a …

Total answers: 2

How to use tkinter to bind operators like +-*/?

How to use tkinter to bind operators like +-*/? Question: i want to use bind in tkinter to detect if +-*/ is pressed. Is this possible? i’ve checked a lot on the internet and here is the code,i want to know what should i filed in the ??? import tkinter as tk class Application(tk.Tk): def …

Total answers: 1

Python tkinter (copy/paste not working with other languages)

Python tkinter (copy/paste not working with other languages) Question: I found out that whenever i switch the language from english to russian tkinter stops reacting to Ctrl+C, Ctrl+V or Ctrl+X. It still works when i switch back to english, even if the text is in russian. I tried all code snippets i could find on …

Total answers: 3

Capture all key-presses in PyQt

Capture all key-presses in PyQt Question: I am trying to capture all of key pressed in my program def keyPressEvent(self, event): event = event.key() if (event == QtCore.Qt.Key_Q): print (‘Q!.’) That function works fine when i am trying to capture keys in my window. (in this case Q_Key) But if the key was pressed in …

Total answers: 1

Capture Control-C in Python

Capture Control-C in Python Question: I want to know if it’s possible to catch a Control-C in python in the following manner: if input != contr-c: #DO THINGS else: #quit I’ve read up on stuff with try and except KeyboardInterrupt but they’re not working for me. Asked By: pauliwago || Source Answers: From your comments, …

Total answers: 2

How to generate keyboard events?

How to generate keyboard events? Question: short summary: I am trying to create a program that will send keyboard events to the computer that for all purposes the simulated events should be treated as actual keystrokes on the keyboard. original post: I am looking for a way to generate keyboard events using python. Assume that …

Total answers: 12