标签:
通过oemKeyScan和MapVirtualKey函数
oemKeyScan可以获得扫描码以及转换状态,状态有shift被按下,ctrl被按下,alt被按下等等。
MapVirtualKey将一虚拟键码翻译(映射)成一扫描码或一字符值,或者将一扫描码翻译成一虚拟键码。
1 DWORD sc, shift; 2 unsigned char vkey; 3 char a; 4 CString str = "abc"; 5 for (int i = 0; i<str.GetLength(); i++)//模拟键盘输出str中的字符 6 { 7 a = str.GetAt(i); 8 sc = OemKeyScan(a); 9 shift = sc >> 16; 10 vkey = MapVirtualKey(sc & 0xffff, 1); 11 if (shift) 12 keybd_event(VK_SHIFT, 0, 0, 0); 13 keybd_event(vkey, 0, 0, 0); 14 keybd_event(vkey, 0, KEYEVENTF_KEYUP, 0); 15 if (shift) 16 keybd_event(VK_SHIFT, 0, KEYEVENTF_KEYUP, 0); 17 }
标签:
原文地址:http://www.cnblogs.com/macher/p/4488606.html