当前位置: 代码迷 >> PB >> keybd_event的用法解决办法
  详细解决方案

keybd_event的用法解决办法

热度:67   发布时间:2016-04-29 10:13:16.0
keybd_event的用法
有个DW:dw_long,按焦点顺序有列a,b,c
在一个按钮点击事件中加入以下代码:
dw_long.SetColumn("a")
dw_long.SetFocus()
keybd_event(9, 0, 0 , 0 ) // 按下tab
keybd_event(9, 0, 2, 0 ) // 释放tab 
执行后,列b获取了焦点

将代码改成:
dw_long.SetColumn("a")
dw_long.SetFocus()
keybd_event(9, 0, 0 , 0 ) // 按下tab
keybd_event(9, 0, 2, 0 ) // 释放tab 
dw_long.SetColumn("a")  

本意是想最终焦点还是在列a上但发现代码执行后的结果是,焦点还是在列b
如果我改成:
dw_long.SetColumn("a")
dw_long.SetFocus()
keybd_event(9, 0, 0 , 0 ) // 按下tab
keybd_event(9, 0, 2, 0 ) // 释放tab 
dw_long.SetColumn("a")  
dw_long.SetColumn("b") 

这时候执行结果是焦点在列c了。

为什么会这样呢?我是想在模拟了tab键动作后,再自己定位焦点,但是发现执行的结果却是取了代码中最后setcolumn的列,然后才模拟了tab动作...
请问我应该怎么做才能达到模拟了tab键后再自己定位焦点在其他列上


------解决方案--------------------
dw_long.SetColumn("a")
dw_long.SetFocus()
keybd_event(9, 0, 0 , 0 ) // 按下tab 
keybd_event(9, 0, 2, 0 ) // 释放tab
dw_long.post SetColumn("a")


------解决方案--------------------
Virtual-Key Codes 

--------------------------------------------

The following table shows the symbolic constant names, hexadecimal values, and mouse or keyboard equivalents for the virtual-key codes used by the system. The codes are listed in numeric order. 

Constants

VK_LBUTTON (01)
Left mouse button

VK_RBUTTON (02)
Right mouse button

VK_CANCEL (03)
Control-break processing

VK_MBUTTON (04)
Middle mouse button (three-button mouse)

VK_XBUTTON1 (05)
Windows 2000/XP: X1 mouse button

VK_XBUTTON2 (06)
Windows 2000/XP: X2 mouse button

- (07)
Undefined

VK_BACK (08)
BACKSPACE key

VK_TAB (09)
TAB key

- (0A-0B)
Reserved

VK_CLEAR (0C)
CLEAR key

VK_RETURN (0D)
ENTER key

- (0E-0F)
Undefined

VK_SHIFT (10)
SHIFT key

VK_CONTROL (11)
CTRL key

VK_MENU (12)
ALT key

VK_PAUSE (13)
PAUSE key

VK_CAPITAL (14)
CAPS LOCK key

VK_KANA (15)
Input Method Editor (IME) Kana mode

VK_HANGUEL (15)
IME Hanguel mode (maintained for compatibility; use VK_HANGUL)

VK_HANGUL (15)
IME Hangul mode

- (16)
Undefined

VK_JUNJA (17)
IME Junja mode

VK_FINAL (18)
IME final mode

VK_HANJA (19)
IME Hanja mode

VK_KANJI (19)
IME Kanji mode

- (1A)
Undefined

VK_ESCAPE (1B)
ESC key

VK_CONVERT (1C)
IME convert

VK_NONCONVERT (1D)
IME nonconvert

VK_ACCEPT (1E)
IME accept

VK_MODECHANGE (1F)
IME mode change request

VK_SPACE (20)
SPACEBAR

VK_PRIOR (21)
PAGE UP key

VK_NEXT (22)
PAGE DOWN key

VK_END (23)
END key

VK_HOME (24)
HOME key

VK_LEFT (25)
LEFT ARROW key

VK_UP (26)
UP ARROW key

VK_RIGHT (27)
RIGHT ARROW key

VK_DOWN (28)
DOWN ARROW key

VK_SELECT (29)
SELECT key

VK_PRINT (2A)
PRINT key

VK_EXECUTE (2B)
EXECUTE key

VK_SNAPSHOT (2C)
PRINT SCREEN key

VK_INSERT (2D)
INS key

VK_DELETE (2E)
DEL key

VK_HELP (2F)
HELP key

 (30)
0 key

 (31)
1 key

 (32)
2 key

 (33)
3 key

 (34)
4 key

 (35)
5 key

 (36)
6 key
  相关解决方案