码迷,mamicode.com
首页 > 编程语言 > 详细

控制鼠标键盘 python pywin32 键位查询 win32api

时间:2016-05-06 15:26:06      阅读:6566      评论:0      收藏:0      [点我收藏+]

标签:

python控制键盘鼠标操作

1.下载pywin32 点我下载最新版

2.pywin32资料

资料大多为英文,我只了解一部分,感兴趣请深查
PyWin32 Documentation 点我传送

PyWin32 Documentation ActiveState Docs 点我传送

Win32 How Do I…? by Tim Golden 点我传送

3.举个简单的栗子

#coding:utf-8

‘‘‘
FuncName: pywin32.py
Desc: search key
Date: 2016-05-04 16:00  
Author: johnny
‘‘‘

import win32api
import win32con

‘‘‘ 我想用键盘输入 version.info ‘‘‘

win32api.keybd_event(0x56,0,0,0)     #v    0x56就是v的16进制数,可以是ASCII
win32api.keybd_event(0x45,0,0,0)     #e
win32api.keybd_event(0x52,0,0,0)     #r
win32api.keybd_event(0x53,0,0,0)     #s
win32api.keybd_event(0x49,0,0,0)     #i
win32api.keybd_event(0x4F,0,0,0)     #o
win32api.keybd_event(0x4E,0,0,0)     #n
win32api.keybd_event(0xBE,0,0,0)     #.
win32api.keybd_event(0x49,0,0,0)     #i
win32api.keybd_event(0x4E,0,0,0)     #n
win32api.keybd_event(0x46,0,0,0)     #f
win32api.keybd_event(0x4F,0,0,0)     #o

‘‘‘我想输入下划线‘_‘,使用组合键‘‘‘
win32api.keybd_event(0xA0,0,0,0)                  # shift左
win32api.keybd_event(0xBD,0,0,0)                  # -
win32api.keybd_event(0xBD,0,win32con.KEYEVENTF_KEYUP,0)  #释放按键
win32api.keybd_event(0xA0,0,win32con.KEYEVENTF_KEYUP,0)

‘‘‘ 我想用鼠标操作 ‘‘‘

win32api.mouse_event(win32con.MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0)#按下
win32api.mouse_event(win32con.MOUSEEVENTF_LEFTUP, 0, 0, 0, 0)#弹起

4.进制转换

int(x[,base ])x转换为一个整数    
long(x[,base ])x转换为一个长整数    
float(x)x转换到一个浮点数    
complex(real [,imag ])  创建一个复数    
str(x)                 将对象 x 转换为字符串    
repr(x)                将对象 x 转换为表达式字符串    
eval(str)              用来计算在字符串中的有效Python表达式,并返回一个对象    
tuple(s)               将序列 s 转换为一个元组    
list(s)                将序列 s 转换为一个列表    
chr(x)                 将一个整数转换为一个字符    
unichr(x)              将一个整数转换为Unicode字符    
ord(x)                 将一个字符转换为它的整数值    
hex(x)                 将一个整数转换为一个十六进制字符串    
oct(x)                 将一个整数转换为一个八进制字符串

5.键位查询

16进制:
    ‘backspace‘:0x08,
    ‘tab‘:0x09,
    ‘clear‘:0x0C,
    ‘enter‘:0x0D,
    ‘shift‘:0x10,
    ‘ctrl‘:0x11,
    ‘alt‘:0x12,
    ‘pause‘:0x13,
    ‘caps_lock‘:0x14,
    ‘esc‘:0x1B,
    ‘spacebar‘:0x20,
    ‘page_up‘:0x21,
    ‘page_down‘:0x22,
    ‘end‘:0x23,
    ‘home‘:0x24,
    ‘left_arrow‘:0x25,
    ‘up_arrow‘:0x26,
    ‘right_arrow‘:0x27,
    ‘down_arrow‘:0x28,
    ‘select‘:0x29,
    ‘print‘:0x2A,
    ‘execute‘:0x2B,
    ‘print_screen‘:0x2C,
    ‘ins‘:0x2D,
    ‘del‘:0x2E,
    ‘help‘:0x2F,
    ‘0‘:0x30,
    ‘1‘:0x31,
    ‘2‘:0x32,
    ‘3‘:0x33,
    ‘4‘:0x34,
    ‘5‘:0x35,
    ‘6‘:0x36,
    ‘7‘:0x37,
    ‘8‘:0x38,
    ‘9‘:0x39,
    ‘a‘:0x41,
    ‘b‘:0x42,
    ‘c‘:0x43,
    ‘d‘:0x44,
    ‘e‘:0x45,
    ‘f‘:0x46,
    ‘g‘:0x47,
    ‘h‘:0x48,
    ‘i‘:0x49,
    ‘j‘:0x4A,
    ‘k‘:0x4B,
    ‘l‘:0x4C,
    ‘m‘:0x4D,
    ‘n‘:0x4E,
    ‘o‘:0x4F,
    ‘p‘:0x50,
    ‘q‘:0x51,
    ‘r‘:0x52,
    ‘s‘:0x53,
    ‘t‘:0x54,
    ‘u‘:0x55,
    ‘v‘:0x56,
    ‘w‘:0x57,
    ‘x‘:0x58,
    ‘y‘:0x59,
    ‘z‘:0x5A,
    ‘numpversion.infoad_0‘:0x60,
    ‘numpad_1‘:0x61,
    ‘numpad_2‘:0x62,
    ‘numpad_3‘:0x63,
    ‘numpad_4‘:0x64,
    ‘numpad_5‘:0x65,
    ‘numpad_6‘:0x66,
    ‘numpad_7‘:0x67,
    ‘numpad_8‘:0x68,
    ‘numpad_9‘:0x69,
    ‘multiply_key‘:0x6A,
    ‘add_key‘:0x6B,
    ‘separator_key‘:0x6C,
    ‘subtract_key‘:0x6D,
    ‘decimal_key‘:0x6E,
    ‘pide_key‘:0x6F,
    ‘F1‘:0x70,
    ‘F2‘:0x71,
    ‘F3‘:0x72,
    ‘F4‘:0x73,
    ‘F5‘:0x74,
    ‘F6‘:0x75,
    ‘F7‘:0x76,
    ‘F8‘:0x77,
    ‘F9‘:0x78,
    ‘F10‘:0x79,
    ‘F11‘:0x7A,
    ‘F12‘:0x7B,
    ‘F13‘:0x7C,
    ‘F14‘:0x7D,
    ‘F15‘:0x7E,
    ‘F16‘:0x7F,
    ‘F17‘:0x80,
    ‘F18‘:0x81,
    ‘F19‘:0x82,
    ‘F20‘:0x83,
    ‘F21‘:0x84,
    ‘F22‘:0x85,
    ‘F23‘:0x86,
    ‘F24‘:0x87,
    ‘num_lock‘:0x90,
    ‘scroll_lock‘:0x91,
    ‘left_shift‘:0xA0,
    ‘right_shift ‘:0xA1,
    ‘left_control‘:0xA2,
    ‘right_control‘:0xA3,
    ‘left_menu‘:0xA4,
    ‘right_menu‘:0xA5,
    ‘browser_back‘:0xA6,
    ‘browser_forward‘:0xA7,
    ‘browser_refresh‘:0xA8,
    ‘browser_stop‘:0xA9,
    ‘browser_search‘:0xAA,
    ‘browser_favorites‘:0xAB,
    ‘browser_start_and_home‘:0xAC,
    ‘volume_mute‘:0xAD,
    ‘volume_Down‘:0xAE,
    ‘volume_up‘:0xAF,
    ‘next_track‘:0xB0,
    ‘previous_track‘:0xB1,
    ‘stop_media‘:0xB2,
    ‘play/pause_media‘:0xB3,
    ‘start_mail‘:0xB4,
    ‘select_media‘:0xB5,
    ‘start_application_1‘:0xB6,
    ‘start_application_2‘:0xB7,
    ‘attn_key‘:0xF6,
    ‘crsel_key‘:0xF7,
    ‘exsel_key‘:0xF8,
    ‘play_key‘:0xFA,
    ‘zoom_key‘:0xFB,
    ‘clear_key‘:0xFE,
    ‘+‘:0xBB,
    ‘,‘:0xBC,
    ‘-‘:0xBD,
    ‘.‘:0xBE,
    ‘/‘:0xBF,
    ‘`‘:0xC0,
    ‘;‘:0xBA,
    ‘[‘:0xDB,
    ‘//‘:0xDC,
    ‘]‘:0xDD,
    "‘":0xDE,
    ‘`‘:0xC0}
附个ASCII键位码表:
字母和数字键     数字小键盘的键       功能键         其它键 
         键码        键码          键码           键码 
      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),注意大小写ASCII值不同

控制鼠标键盘 python pywin32 键位查询 win32api

标签:

原文地址:http://blog.csdn.net/z_johnny/article/details/51321287

(2)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!