Pynput键盘记录器仅返回Shift,Command,空格键和Capslock键 [英] Pynput Keylogger Only Returning Shift, Command, Space and Capslock Keys

查看:135
本文介绍了Pynput键盘记录器仅返回Shift,Command,空格键和Capslock键的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望在上一个线程中没有对此进行讨论.我的搜索结果未返回任何相关信息,但请随时赐教!

I hope this hasn't been discussed on a previous thread. My search results returned nothing pertinent but please feel free to enlighten me!

我正在编写一个非常基本的Python键盘记录器(用于较大项目的一部分).我正在使用Pynput侦听击键,并使用日志记录模块将其写入txt文件(请参见下文).到目前为止,它似乎仍在工作,唯一的问题是它只会记录shift,command,space和caps lock键.不会记录所有其他按键,即字母,数字等.

I'm in the process of writing a very basic Python keylogger (for part of a larger project). I'm using pynput to listen for keystrokes and the logging module to write these to a txt file (see below). It seems to be working so far with the only problem being that it will only log the shift, command, space and caps locks keys. All other keystrokes i.e. letters, numbers etc. are not logged.

我正在运行OSX 10.12(Sierra),Python 3.5.2.

I'm running OSX 10.12 (Sierra), Python 3.5.2.

任何可能的原因(和可能的解决方案)的建议/想法都将受到极大的赞赏.

Any suggestions/ideas as to why this might be (and possible solutions) would be hugely appreciated.

谢谢.

    from pynput.keyboard import Key, Listener
    import logging

    log_dir = ""

    logging.basicConfig(filename=(log_dir + 'key_log.txt'), level=logging.DEBUG, format='%(asctime)s: %(message)s')

    def on_press(key):
        logging.info(str(key))

    with Listener(on_press=on_press) as listener:
        listener.join() 

推荐答案

快速解决方案:以root身份运行

手册有用.

Mac OSX 出于安全原因,最新版本的Mac OSX限制了对键盘的监视.因此, 以下必须为真:

Mac OSX Recent versions of Mac OSX restrict monitoring of the keyboard for security reasons. For that reason, one of the following must be true:

  • 该进程必须以root用户身份运行.

  • 您的应用程序必须在启用辅助访问权限"下列为白色 设备.请注意,这可能需要 打包您的应用程序,因为否则必须将整个Python安装列入白名单.

  • The process must run as root.

  • Your application must be white listed under Enable access for assistive devices. Note that this might require that you package your application, since otherwise the entire Python installation must be white listed.

请注意,这不适用于监视鼠标或触控板.

Please note that this does not apply to monitoring of the mouse or trackpad.

这篇关于Pynput键盘记录器仅返回Shift,Command,空格键和Capslock键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆