keybd_event函数详解(请别忽视了scan codes!)
来源:互联网 发布:麻将胡牌算法 编辑:程序博客网 时间:2024/05/17 06:54
Introduction
Simulation of a keyboard input is a well known concept for those who are all familiar with Visual Basic. SendKeys()
in Visual Basic does all the things, if you want to do anything without keyboard. But what is in SendKeys()
function? What does it do? Can we do such a thing with Visual C++? This article is the answer. I think this will be useful for beginners who are all just trying to do something different with VC++. Let us get into the steps�
Function Syntax
void keybd_event(BYTE bVirtualKey, BYTE bScanCode, DWORD dwFlags, DWORD dwExtraInfo);
bVirtualKey //Virtual Keycode of keys. E.g., VK_RETURN, VK_TAB�
bScanCode //Scan Code value of keys. E.g., 0xb8 for �Left Alt� key.
dwFlags //Flag that is set for key state. E.g., KEYEVENTF_KEYUP.
dwExtraInfo //32-bit extra information about keystroke.
Function Details:
bVirtualKey
Virtual keycode that has to be send as key input. The following are the available predefined virtual key codes:
VK_NUMPAD7
0x67VK_BACK
0x08VK_NUMPAD8
0x68VK_TAB
0x09VK_NUMPAD9
0x69VK_RETURN
0x0DVK_MULTIPLY
0x6AVK_SHIFT
0x10VK_ADD
0x6BVK_CONTROL
0x11VK_SEPARATOR
0x6CVK_MENU
0x12VK_SUBTRACT
0x6DVK_PAUSE
0x13VK_DECIMAL
0x6EVK_CAPITAL
0x14VK_DIVIDE
0x6FVK_ESCAPE
0x1BVK_F1
0x70VK_SPACE
0x20VK_F2
0x71VK_END
0x23VK_F3
0x72VK_HOME
0x24VK_F4
0x73VK_LEFT
0x25VK_F5
0x74VK_UP
0x26VK_F6
0x75VK_RIGHT
0x27VK_F7
0x76VK_DOWN
0x28VK_F8
0x77VK_PRINT
0x2AVK_F9
0x78VK_SNAPSHOT
0x2CVK_F10
0x79VK_INSERT
0x2DVK_F11
0x7AVK_DELETE
0x2EVK_F12
0x7BVK_LWIN
0x5BVK_NUMLOCK
0x90VK_RWIN
0x5CVK_SCROLL
0x91VK_NUMPAD0
0x60VK_LSHIFT
0xA0VK_NUMPAD1
0x61VK_RSHIFT
0xA1VK_NUMPAD2
0x62VK_LCONTROL
0xA2VK_NUMPAD3
0x63VK_RCONTROL
0xA3VK_NUMPAD4
0x64VK_LMENU
0xA4VK_NUMPAD5
0x65VK_RMENU
0xA5VK_NUMPAD6
0x66Character key can be converted into virtual key using
VkKeyScan(TCHAR ch)
function.bScanCode
Scan code is the hardware key code for the key (make and break codes). The following are the available scan codes (break code will be used in this parameter).
dwFlags
A set of flag bits that specify various aspects of function operation. An application can use any combination of the following predefined constant values to set the flags.
ValueMeaningKEYEVENTF_EXTENDEDKEY
If specified, the scan code was preceded by a prefix byte having the value 0xE0 (224).KEYEVENTF_KEYUP
If specified, the key is being released. If not specified, the key is being depressed.dwExtraInfo
32-bit extra information along with the keyboard input.
Example Code
// Simulating a Alt+Tab keystrokekeybd_event(VK_MENU,0xb8,0 , 0); //Alt Presskeybd_event(VK_TAB,0x8f,0 , 0); // Tab Presskeybd_event(VK_TAB,0x8f, KEYEVENTF_KEYUP,0); // Tab Releasekeybd_event(VK_MENU,0xb8,KEYEVENTF_KEYUP,0); // Alt Release// Simulating a Ctrl+A keystrokekeybd_event(VK_CONTROL,0x9d,0 , 0); // Ctrl Presskeybd_event(VkKeyScan(�A�),0x9e,0 , 0); // �A� Presskeybd_event(VkKeyScan(�A�),0x9e, KEYEVENTF_KEYUP,0); // �A� Releasekeybd_event(VK_CONTROL,0x9d,KEYEVENTF_KEYUP,0); // Ctrl Release
Conclusion
This article may not be that much detailed. None of the articles can satisfy one's expectations. But, each article should be a seed for your technical growth. Thus, I believe that this would be a seed. Thank you all.
License
This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)
- keybd_event函数详解(请别忽视了scan codes!)
- 软件搞好了可别忽视了硬件
- keybd_event详解
- keybd_event函数
- scan函数函数用法详解
- 请TMD别再意淫乔布斯了!
- 请别埋没了URL Routing
- 分享,请不要忽视了作者的版权
- SendInput代替了keybd_event
- INT 16 - Keyboard Scan Codes
- 模拟按键函数Keybd_event
- keybd_event函数用法
- keybd_event,mouse_event函数使用方法
- VC++模拟键盘输入(keybd_event() 、 PostMessage() /SendMessage()、SendInput())详解
- VC++模拟键盘输入(keybd_event() 、 PostMessage() /SendMessage()、SendInput())详解
- 别再耍流氓了: 请别再用strcpy, 而用strncpy
- 别再耍流氓了: 请别再用strcpy, 而用strncpy 或stpcpy, strlcpy (linux)
- VB keybd_event函数怎么用
- extjs jsonreader groupgrid
- 行列转换-->动态SQL语句例子
- flex as3开源组件
- 使用poi
- 一道关于截取字符串的java面试题
- keybd_event函数详解(请别忽视了scan codes!)
- 各种数据库连接java的驱动名和语句
- dfggfg
- Linux操作系统中/sbin/init程序的执行过程
- Oracle RAC相关以及基础知识
- Oracle 10g 的后台进程
- 学习网址
- MySQL Proxy安装和使用(一)
- 2008计算机系研究生所签单位工资解密