pynput

ImportError: No module named pynput.keyboard

假如想象 提交于 2020-11-30 00:07:42
问题 I have a problem and I can't find anything to help.The idea is that I can't import pynput. I did the pip install and this is what it shows: > Traceback (most recent call last): File "sb.py", line 1, in <module> from pynput.keyboard import Key, Controller ImportError: No module named pynput.keyboard I tried again pip install pynput and it shows Requirement already satisfied Here is the code, i don't know if it helps but there you go: from pynput.keyboard import Key, Controller def game():

pynput doesn't work as intended regarding mouse clicking and button pressing

情到浓时终转凉″ 提交于 2020-07-20 03:49:30
问题 My goal is to run different codes with various hotkeys. I'm using pynput. The problem is that the script doesn't work normally. The code is as follows: import pynput, pyperclip, re, time mouse = pynput.mouse.Controller() keyboard = pynput.keyboard.Controller() def on_activate_h(): mouse.position = (500, 500) mouse.click(pynput.mouse.Button.left, 1) time.sleep(1) mouse.position = (600, 600) mouse.click(pynput.mouse.Button.left, 1) time.sleep(1) mouse.position = (800, 800) mouse.click(pynput

Checking a specific key with pynput in Python

孤街浪徒 提交于 2020-05-27 13:21:06
问题 dpressed = 0 def on_press(key): if key == ('d'): global dpressed dpressed+=1 logging.info("D: %s" % dpressed) When I run this code and press d, nothing happens, which I suspect is because the key needs to be called something else when checked. Does someone know what it should be? 回答1: For anyone else that may have this problem, I imported KeyCode from pynput.keybord at the top. Then I changed ('d') to KeyCode.from_char('d'). This should work for anyone with this problem. There is a great

Listening to specific keys with pynput.Listener and keylogger?

﹥>﹥吖頭↗ 提交于 2020-03-25 19:01:29
问题 I have the following python script below: But I want to "listen" or, if it's enough, just "record" to my log.txt, the following keys: Key.left and Key.up. How can I cause this restriction? This question is similar but the code structures of her responses are somewhat different and would require a major change to allow the keylogger and this restriction on the Listener . And this other question seems to me to be a potential source of inspiration for finding a method of solution. I spent some

How to run pynput.Listener simultaneously with tkinter.Tk().mainloop()

*爱你&永不变心* 提交于 2020-02-25 05:51:21
问题 I am a teacher. I teach math, but since education is facing human resources crisis, I have some additional duties. I teach kids a bit of programming, they do quite well. Now I'd like to make with them a snake game, but I have a problem achieving multithreading in my GUI app. I found similar cases but no solutions. Like here: Using the keyboard to move the character in a maze and here: Tkinter.Tk() and threading def on_press(key): print('{0} pressed'.format(key)) def on_release(key): if key ==

pynput keyboard listener does not detect keys on Mac OS X

别等时光非礼了梦想. 提交于 2020-02-25 04:03:29
问题 I am using pynput to record keystrokes via Listener on OS X Mojave. I am using Pycharm as my IDE for running the code. I was not able to get it to work using the same example from the pynput site. from pynput.keyboard import Listener as key_listener class recorder: def on_press(self, key): print(key) def on_release(self, key): print(key) if __name__ == "__main__": testme = recorder() with key_listener(on_press=testme.on_press, on_release=testme.on_release) as listener: listener.join() I did

Listening for specific keys with pynput

人走茶凉 提交于 2020-01-23 17:42:48
问题 I'd like my code to listen for user input, and do something if key c is pressed, and something else if key v is pressed. I've managed to do it using global , but it feels like an ugly hack : from pynput import keyboard def on_press(key): try: global user_input if key.char == "c": user_input = "c" elif key.char == "v": user_input == "v" except AttributeError: pass def on_release(key): if key == keyboard.Key.esc: # Stop listener return False def wait_for_user_input(): global user_input listener

Using the keyboard to move the character in a maze

拈花ヽ惹草 提交于 2019-12-11 17:30:15
问题 I have created a simple maze and I have no way to move the character to the objective. The maze is on a TKinter window so I don't know if that is stopping the code from running. I have tried using pynput, which has worked in a seperate program without a tkinter window running, so I dont get whats wrong at all. def level1(): x=1 startx = 1 objectivex = 10 y=1 starty=1 objectivey=10 val_in_row = [[0,1,2,3,4,5,6,7,8,9,10,11],[0,3,7,11],[0,1,5,7,8,9,11],[0,3,5,6,11],[0,2,4,7,9,10,11],[0,4,6,10,11

How to keep pynput and ctypes from clashing?

荒凉一梦 提交于 2019-12-04 22:36:43
I'm using this gem from somewhere on this site. import ctypes import pynput SendInput = ctypes.windll.user32.SendInput W = 0x11 A = 0x1E S = 0x1F D = 0x20 # C struct redefinitions PUL = ctypes.POINTER(ctypes.c_ulong) class KeyBdInput(ctypes.Structure): _fields_ = [("wVk", ctypes.c_ushort), ("wScan", ctypes.c_ushort), ("dwFlags", ctypes.c_ulong), ("time", ctypes.c_ulong), ("dwExtraInfo", PUL)] class HardwareInput(ctypes.Structure): _fields_ = [("uMsg", ctypes.c_ulong), ("wParamL", ctypes.c_short), ("wParamH", ctypes.c_ushort)] class MouseInput(ctypes.Structure): _fields_ = [("dx", ctypes.c_long