- 用方向键转移焦点及回车键触发
-
- 窗口的key事件:
- GRAPHICOBJECT cb_control //定义环境变量
- CHOOSE CASE KEY
- CASE //按光标右键右移焦点
- keybd_event(9,0,0,0)
- keybd_event(9,0,2,0)
- CASE //按光标下键右移焦点
- keybd_event(9,0,0,0)
- keybd_event(9,0,2,0)
- CASE //按光标左键左移焦点
- keybd_event(16,0,0,0)
- keybd_event(9,0,0,0)
- keybd_event(16,0,2,0)
- keybd_event(9,0,2,0)
- CASE //按光标上键左移焦点
- keybd_event(16,0,0,0)
- keybd_event(9,0,0,0)
- keybd_event(16,0,2,0)
- keybd_event(9,0,2,0)
- CASE //回车键触发焦点处控件
- cb_control = GETFOCUS()
- IF TypeOf(cb_control)= THEN
- Triggerevent(cb_control,
- END IF
- END CHOOSE
- 问:请问如何实现利用左右键及回车键进行列的焦点转移?
- 答:这要用到Windows中的API函数keybd_event()
- ①定义API:
- Subroutine keybd_event(uint bVk,uint bScan,long dwFlags,long dwExtraInfo ) library "user32.dll"
-
- ②自定义一用户事件(ue_keydown ID:pbm_dwnkey):
- integer VK_TAB = 09
- integer VK_SHIFT = 16
- if key = then
- keybd_event(VK_SHIFT,0,0,0) //按下shift
- keybd_event(VK_TAB,0,0,0) //按下tab
- keybd_event(VK_TAB,0,2,0) //释放tab
- keybd_event(VK_SHIFT,0,2,0) //释放shift
- return 1
- end if
- if key = or key= then
- keybd_event(VK_TAB,0,0,0) //按下tab
- keybd_event(VK_TAB,0,2,0) //释放tab
- return 1
- end if
- 如若只是想利用ENTER键来实现TAB键的功能可以用以下代码:
- if key= then
- Send(Handle(this),256,9,Long(0,0)) //发送TAB键
- Return 1 //取消原ENTER键的动作
- end if
02-09 23:13