MacBook Air键盘记录器无法识别Pynput

时间:2018-07-25 18:27:48

标签: python macos keylogger pynput

我在Windows计算机上设计了一个按键记录器,但是当我将其移动到个人Mac上时,代码停止工作。通过pip安装,我似乎已经成功下载了pynput,但是当我运行代码时,出现错误消息:Traceback(最近一次调用):文件“ /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()

0 个答案:

没有答案