我在一台windows电脑上设计了一个键记录程序,但是当我把它移到我的个人mac上时,代码就停止工作了。通过pip安装,我似乎成功地下载了pynput,但是当我运行代码时,我得到了一条错误消息:Traceback(最近一次调用最后一次):File“/Users/Ben/Desktop/code/key”_logger.py“,第6行,英寸
从pynput导入键盘
ModuleNotFoundError:没有名为“pynput”的模块keys = []
import threading
from threading import Thread
from pynput import keyboard
from pynput import mouse
def on_press(key):
f = open('keylog.txt','a+')
keys.append(key)
f.write(str(key) + " ")
yes = True
f.close()
def on_click(x, y, button, pressed):
f = open('keylog.txt','a+')
keys.append(('{0} at {1}'.format('Pressed',(x,y))))
f.write(str(('{0} at {1}'.format('Pressed',(x,y)))))
f.close()
def func1():
with keyboard.Listener(on_press = on_press) as listener:
listener.join()
def func2():
with mouse.Listener(on_click=on_click) as listener1:
listener1.join()
if __name__ == '__main__':
Thread(target=func1).start()
Thread(target=func2).start()