代码如下在key(keycode key ,unsignedlong keyflags)函数中
GraphicObject which_control
commandbutton cb_which
tab tab_which
if key = KeyEnter! then
which_control =getfocus()
choose case typeof(which_control)
case commandbutton!
cb_which = which_control
if cb_which = cb_1 then
cb_1.triggerevent(clicked!)
end if
return
end choose
keybd_event(9,0,0,0)
keybd_event(9,0,2,0)
end if
//这是很简单的enter键变为tab的一段代码,pb自带的例子也有相似代码,我在tab order 也已经将顺序改好,不过在调试过程中,getfocus()方法始终返回null,很是费解,望高手指明。
------解决方案--------------------
debug时取到的就是空,直接运行时取值是没问题的,你可以在确定焦点是你的按钮时:
choose case typeof(which_control)
case commandbutton!
这里加一句 messagebox("",abc)
会发现 abc弹出来了 此时debug的话 getfocus还会是空 为啥我不知道。
如果楼主想实现enter键变为tab功能的话
if key = KeyEnter! then
Send(Handle(This),256,9,Long(0,0))
return 1
end if
这句话就是模拟tab键了