V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
commoccoom
V2EX  ›  Python

用 Python 模拟键盘事件

  •  
  •   commoccoom · 2015-10-04 16:44:41 +08:00 · 5041 次点击
    这是一个创建于 3119 天前的主题,其中的信息可能已经有所发展或是发生改变。
    当按下键盘 E 键 时 , E , Q 键都按了

    给几个关键词也行,搜索了一下,没找到可行的方法
    10 条回复    2015-10-05 20:26:15 +08:00
    fasling
        1
    fasling  
       2015-10-04 16:53:16 +08:00   ❤️ 1
    用 PyHook 拦截键盘事件, 获取到 E 键按下的消息.
    用 SendKeys 模拟键盘消息, 按下 E 键和 Q 键.
    Windows 下应该没问题,Mac 下估计不行.
    楼主是想自己写游戏助手?
    shoaly
        2
    shoaly  
       2015-10-04 16:56:45 +08:00
    auto hot key 已经非常简单易用了... 不用折腾 python 了...
    zckevin
        3
    zckevin  
       2015-10-04 17:14:49 +08:00   ❤️ 1
    commoccoom
        4
    commoccoom  
    OP
       2015-10-04 17:22:20 +08:00
    @shoaly

    就是想用 Python 试试,没别的
    commoccoom
        5
    commoccoom  
    OP
       2015-10-04 17:23:34 +08:00
    @zckevin

    win 系统
    tcsky
        6
    tcsky  
       2015-10-04 21:55:13 +08:00
    建议试试大漠插件,写游戏脚步的人常用的,
    不需要那么复杂功能的话直接用 win32com
    commoccoom
        7
    commoccoom  
    OP
       2015-10-04 22:12:47 +08:00
    @fasling
    https://gist.github.com/chnt7305/e546a629b40b8bff55d7

    找到了一个例子,但是怎么获取 E 键的信息 这里只有所有按键的信息
    fasling
        8
    fasling  
       2015-10-05 00:34:03 +08:00
    @commoccoom
    你不都获取到所有的按键了嘛?看看哪个是 E 不就行了。
    比如这样的:
    if event.Key == 'E':
    print "按下了 E"
    commoccoom
        9
    commoccoom  
    OP
       2015-10-05 08:20:32 +08:00
    @fasling
    行了,谢谢!
    w88975
        10
    w88975  
       2015-10-05 20:26:15 +08:00
    @tcsky 表示用大漠写游戏外挂挺好使的 大部分语言都能胜任。
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   5208 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 29ms · UTC 09:22 · PVG 17:22 · LAX 02:22 · JFK 05:22
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.