Python模拟键盘输入和鼠标操作

一、Python键盘输入模拟

import win32api

import win32con

win32api.keybd_event(17,0,0,0)  #ctrl键位码是17

win32api.keybd_event(86,0,0,0)  #v键位码是86

win32api.keybd_event(86,0,win32con.KEYEVENTF_KEYUP,0) #释放按键

win32api.keybd_event(17,0,win32con.KEYEVENTF_KEYUP,0)

附个键位码表:

字母和数字键     数字小键盘的键       功能键         其它键

键   键码     键   键码       键   键码     键      键码

A   65       0   96        F1   112     Backspace    8

B   66       1   97        F2   113     Tab       9

C   67       2   98        F3   114     Clear      12

D   68       3   99        F4   115     Enter      13

E   69       4   100       F5   116     Shift      16

F   70       5   101       F6   117     Control     17

G   71       6   102       F7   118      Alt       18

H   72       7   103       F8   119     Caps Lock    20

I   73       8   104       F9   120     Esc       27

J   74       9   105       F10  121     Spacebar    32

K   75       *   106       F11  122     Page Up     33

L   76       +   107       F12  123     Page Down    34

M   77       Enter 108       --   --      End       35

N   78       -   109       --   --       Home      36

O   79       .   110       --   --      Left Arrow   37

P   80       /   111       --   --      Up Arrow    38

Q   81       --   --       --   --      Right Arrow   39

R   82       --   --       --   --      Down Arrow    40

S   83       --   --       --   --      Insert      45

T   84       --   --       --   --      Delete      46

U   85       --   --       --   --      Help       47

V   86       --   --       --   --      Num Lock     144

其他未列出的字母和数字键盘为:ord(c)

二、 使用windll.user32实现鼠标模拟

from ctypes import *

windll.user32.SetCursorPos(100, 100)

三. 使用AutoItX实现鼠标模拟

#将AutoItX3.dll 文件复制到 window目录然后注册一下

regsvr32.exe AutoItX3.dll

from win32com.client import Dispatch

def enter_game():

AutoItX = Dispatch( "AutoItX3.Control" )

# Block All Input

AutoItX.BlockInput( 1 )

AutoItX.Sleep( 20000 )

if AutoItX.WinActivate( GAME_WINDOW_TITLE, '' ):

pass

else:

if AutoItX.WinWaitActive( GAME_WINDOW_TITLE, '', 8 ):

pass

else:

# Unblock input

AutoItX.BlockInput( 0 )

return False

AutoItX.WinSetTitle( GAME_WINDOW_TITLE, '', _pre_title )

AutoItX.WinSetState( _pre_title, '', AutoItX.SW_MAXIMIZE )

AutoItX.Sleep( 5000 )

AutoItX.MouseMove( 462, 396, 10 )

AutoItX.MouseClick( "left" )

AutoItX.Sleep( 1000 )

AutoItX.Send( GAME_ACCT_NAME )

AutoItX.Sleep( 1000 )

AutoItX.MouseMove ( 462, 472, 10 )

AutoItX.MouseClick( "left" )

AutoItX.Sleep( 1000 )

AutoItX.Send( GAME_ACCT_PASS )

AutoItX.Send( "{ENTER}" )

AutoItX.Sleep( 10000 )

# Unblock input

AutoItX.BlockInput( 0 )

return True

Python模拟键盘输入和鼠标操作的更多相关文章

  1. 使用C#模拟键盘输入、鼠标移动和点击、设置光标位置及控制应用程序的显示

    1.模拟键盘输入(SendKeys) 功能:将一个或多个按键消息发送到活动窗口,就如同在键盘上进行输入一样. 语法:SendKeys.Send(string keys);SendKeys.SendWa ...

  2. python 模拟键盘输入

    备忘录 import win32api import win32con win32api.keybd_event(17,0,0,0) #ctrl键位码是17 win32api.keybd_event( ...

  3. SendInput模拟键盘输入的问题

    SendInput模拟键盘输入的问题  http://www.cnblogs.com/yedaoq/archive/2010/12/30/1922305.html 最近接触到这个函数,因此了解了一下, ...

  4. VB模拟键盘输入的N种方法

    VB模拟键盘输入的N种方法http://bbs.csdn.net/topics/90509805hd378发表于: 2006-12-24 14:35:39用VB模拟键盘事件的N种方法 键盘是我们使用计 ...

  5. 用Delphi模拟键盘输入

    在Windows大行其道的今天,windows界面程序受到广大用户的欢迎.对这些程序的操作不外乎两种,键盘输入控制和鼠标输入控制.有时,对于繁杂的,或重复性的操作,我们能否通过编制程序来代替手工输入, ...

  6. 【转】C# winform 加载网页 模拟键盘输入自动接入访问网络

    [转]C# winform 加载网页 模拟键盘输入自动接入访问网络 声明: 本文原创,首发于博客园 http://www.cnblogs.com/EasyInvoice/p/6070563.html  ...

  7. VC 模拟键盘输入

    转载请注明来源:https://www.cnblogs.com/hookjc/ vc模拟键盘输入keybd_event(VK_LWIN, 0, 0 ,0);keybd_event('M', 0, 0 ...

  8. 模拟键盘输入首先要用到一个API函数:keybd_event

    转自:http://www.cnblogs.com/cpcpc/archive/2011/02/22/2123055.html 模拟键盘输入首先要用到一个API函数:keybd_event. 模拟按键 ...

  9. 微信小程序车牌号码模拟键盘输入

    微信小程序车牌号码模拟键盘输入练习, 未经允许,禁止转载,抄袭,如需借鉴参考等,请附上该文章连接. 相关资料参考:https://blog.csdn.net/littlerboss/article/d ...

随机推荐

  1. poj2187

    求最远点对,这是一道经典的旋转卡壳的题目话说由于是前年写的,之后就没怎么研究过计算几何了……感觉都不大记得清了,来稍微回忆一下……首先最远点对一定出现在凸包上显然,然后穷举肯定不行,这时候就需要旋转卡 ...

  2. 升级yosemite后java出错的解决

    昨天升级mac os到yosemite后,因为是系统整体升级,有一些在设置会丢失,这是后话,先说说我在执行一个需要java参与的程序的时候得到如下错误: Error: JAVA_HOME is not ...

  3. Linux kernel ‘lbs_debugfs_write’函数数字错误漏洞

    漏洞名称: Linux kernel ‘lbs_debugfs_write’函数数字错误漏洞 CNNVD编号: CNNVD-201311-421 发布时间: 2013-11-29 更新时间: 2013 ...

  4. [Bhatia.Matrix Analysis.Solutions to Exercises and Problems]ExI.1.1

    Given any $k$-tupel of linearly independent vectors $X$ as above, there exists a $k$-tuple $Y$ biort ...

  5. Git branch (分支学习)

    以前总结的一些git操作,分享在这里. Git 保存的不是文件差异或者变化量,而只是一系列文件快照.   - 列出当前所有分支 git branch <--merge> | <--n ...

  6. linux驱动程序之电源管理之Run-time PM 详解(4)

    Run-time PM. 每个device或者bus都会向run-time PM core注册3个callback   struct dev_pm_ops { ... int (*runtime_su ...

  7. HDU FatMouse's Speed 基本DP

    题意:要求找到的体重递增,速度递减的老鼠,并且输出最长的长度数,而且输出各自的序列数.Special Judge 思路:先按体重由小到大排序,再找最长速度递减序列. 转移方程:mou[i].w> ...

  8. Codevs 1222 信与信封问题 二分图匹配,匈牙利算法

    题目: http://codevs.cn/problem/1222/ 1222 信与信封问题   时间限制: 1 s   空间限制: 128000 KB   题目等级 : 钻石 Diamond 题解 ...

  9. The iOS Design Cheat Sheet 界面设计速参

    http://ivomynttinen.com/blog/the-ios-7-design-cheat-sheet/ With the release of iOS 7, app designers ...

  10. hdoj 2568 前进

    前进 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submissi ...