GUI界面上如何用方向键箭头控制光标自由移动[已解决]
本帖最后由 cashiba 于 2017-4-20 21:34 编辑#include <ButtonConstants.au3>
#include <ComboConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
Global $yonghuming,$shangpingmingcheng,$shuliang,$fapiaohaoma,$danwei,$danjia,$jiage,$zongjia,$tianjia,$daying,$neirong
_maingui()
#Region ### START Koda GUI section ### Form=
Func _maingui()
$Form1 = GUICreate("Form1", 634, 476, 187, 124)
$Label1 = GUICtrlCreateLabel("", 248, 8, 112, 31)
GUICtrlSetFont(-1, 20, 400, 0, "宋体")
$Label2 = GUICtrlCreateLabel("用户名称:", 32, 48, 63, 17)
GUICtrlSetFont(-1, 10, 400, 0, "宋体")
$yonghuming = GUICtrlCreateInput("", 128, 48, 121, 21)
$Label3 = GUICtrlCreateLabel("号码:", 288, 48, 69, 17)
GUICtrlSetFont(-1, 10, 400, 0, "宋体")
$fapiaohaoma = GUICtrlCreateInput("", 392, 48, 121, 21)
$shangpingmingcheng = GUICtrlCreateCombo("", 128, 96, 121, 25, BitOR($CBS_DROPDOWN,$CBS_AUTOHSCROLL))
GUICtrlSetData(-1, "1|2|3|4|5|6|7|8|9|")
$Label4 = GUICtrlCreateLabel("品名:", 32, 96, 64, 17)
$Label5 = GUICtrlCreateLabel("单位:", 288, 96, 40, 17)
$danwei = GUICtrlCreateCombo("", 392, 96, 121, 25, BitOR($CBS_DROPDOWN,$CBS_AUTOHSCROLL))
GUICtrlSetData(-1, "1|2|3|4|5|6|7|8|9")
$Label6 = GUICtrlCreateLabel("数量:", 40, 144, 40, 17)
$shuliang = GUICtrlCreateInput("", 128, 144, 121, 21,$ES_NUMBER)
$Label7 = GUICtrlCreateLabel("单价:", 288, 144, 40, 17)
$danjia = GUICtrlCreateInput("", 392, 144, 121, 21,$ES_NUMBER)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
EndFunc
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
EndSwitch
WEnd如上GUI界面里,默认可以用Tab定向移动光标。但是总不如用四向箭头自由移动光标。
请问大虾们如何用键盘上下左右方向键控制光标在控件间自由移动涅? 本帖最后由 afan 于 2017-3-29 13:42 编辑
发帖不要有“发\票”这些敏感词
如果编辑就去掉这些,不然再审核我就直接删了。
GUISetAccelerators 设置方向键的快捷方式 即可 原来是fa\piao的原因.....
代码是借用当时正在看的一个实例里的框架,又过了两天,对代码里面的文本词语没什么印象...
还以为是自己的描述语言有fa或piao什么的情况。现在明白了....
A大已经指明了解决办法,那也算解决啦
剩下的就是学习GUISetAccelerators函数了。 没办法实现的 学习了 还不清楚有这个 GUISetAccelerators 感谢分享。 用模拟按键 本帖最后由 cashiba 于 2017-4-14 21:29 编辑
#include <ButtonConstants.au3>
#include <ComboConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <Array.au3>
Opt("GUIOnEventMode", 1)
#Region ### START Koda GUI section ### Form=
$hForm = GUICreate("Form", 634, 376)
GUISetOnEvent($GUI_EVENT_CLOSE, "SEvents")
$iDumyu = GUICtrlCreateDummy()
$iDumyd = GUICtrlCreateDummy()
$iDumyl = GUICtrlCreateDummy()
$iDumyr = GUICtrlCreateDummy()
Dim $Quickeys = [["{UP}",$iDumyu],["{DOWN}",$iDumyd],["{LEFT}",$iDumyl],["{RIGHT}",$iDumyr]]
GUISetAccelerators($Quickeys,$hForm)
for $i=0 to 3
GUICtrlSendToDummy($Quickeys[$i], 1)
GUISetOnEvent($Quickeys[$i], "OnDummyEvents")
Next
$Label1 = GUICtrlCreateLabel("数据录入窗口", 248, 8, 224, 31)
GUICtrlSetFont(-1, 20, 400, 0, "宋体")
$Label2 = GUICtrlCreateLabel("户名:", 32, 48, 63, 17)
GUICtrlSetFont(-1, 10, 400, 0, "宋体")
$Input1 = GUICtrlCreateInput("", 128, 48, 121, 21)
$Label3 = GUICtrlCreateLabel("号码:", 288, 48, 69, 17)
GUICtrlSetFont(-1, 10, 400, 0, "宋体")
$Input2 = GUICtrlCreateInput("", 392, 48, 121, 21)
$Label4 = GUICtrlCreateLabel("品名:", 32, 96, 64, 17)
$combo1 = GUICtrlCreateCombo("", 128, 96, 121, 25, BitOR($CBS_DROPDOWN,$CBS_AUTOHSCROLL))
GUICtrlSetData(-1, "1|2|3|4|5|6|7|8|9|")
$Label5 = GUICtrlCreateLabel("单位:", 288, 96, 40, 17)
$combo2 = GUICtrlCreateCombo("", 392, 96, 121, 25, BitOR($CBS_DROPDOWN,$CBS_AUTOHSCROLL))
GUICtrlSetData(-1, "1|2|3|4|5|6|7|8|9")
$Label6 = GUICtrlCreateLabel("数量:", 32, 144, 40, 17)
$Input3 = GUICtrlCreateInput("", 128, 144, 121, 21,$ES_NUMBER)
$Label7 = GUICtrlCreateLabel("单价:", 288, 144, 40, 17)
$Input4 = GUICtrlCreateInput("", 392, 144, 121, 21,$ES_NUMBER)
$buton1 = GUICtrlCreateButton("确定",150, 244, 121, 45)
$buton2 = GUICtrlCreateButton("取消",310, 244, 121, 45)
GUICtrlSetOnEvent($buton1, "OKPressed")
GUICtrlSetOnEvent($buton2, "NoPressed")
GUISetState(@SW_SHOW)
While 1
Sleep(10)
WEnd
Func SEvents()
Select
Case @GUI_CtrlId = $GUI_EVENT_CLOSE
Exit
EndSelect
EndFunc
Func OnDummyEvents()
Select
Case GUICtrlRead($iDumyu)
Send("+{TAB 2}")
Case GUICtrlRead($iDumyd)
Send("{TAB 2}")
Case GUICtrlRead($iDumyl)
Send("+{TAB}")
Case GUICtrlRead($iDumyr)
Send("{TAB}")
EndSelect
EndFunc
Func OKPressed()
exit
EndFunc ;==>OKPressed
Func NoPressed()
Exit
EndFunc还差一点就成功了.....
不知哪里没写对
路过的大侠请指点哈
我等新手青木们可以顺便了解一下虚拟控件、快捷键以及事件模式等
{:face (52):} 回复 8# cashiba
用最简单的思路
#include <ButtonConstants.au3>
#include <ComboConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <Array.au3>
Opt("GUIOnEventMode", 1)
Global $Input, $hHandle
#Region ### START Koda GUI section ### Form=
$hForm = GUICreate("Form", 634, 376)
GUISetOnEvent($GUI_EVENT_CLOSE, "SEvents")
$iUP = GUICtrlCreateButton("", 0, 0, 0, 0)
GUICtrlSetOnEvent(-1, "OnDummyEvents")
$iDOWN = GUICtrlCreateButton("", 1, 1, 0, 0)
GUICtrlSetOnEvent(-1, "OnDummyEvents")
$iLEFT = GUICtrlCreateButton("", 2, 2, 0, 0)
GUICtrlSetOnEvent(-1, "OnDummyEvents")
$iRIGHT = GUICtrlCreateButton("", 3, 3, 0, 0)
GUICtrlSetOnEvent(-1, "OnDummyEvents")
Dim $Quickeys = [["{UP}",$iUP],["{DOWN}",$iDOWN],["{LEFT}",$iLEFT],["{RIGHT}",$iRIGHT]]
GUISetAccelerators($Quickeys)
$Label1 = GUICtrlCreateLabel("数据录入窗口", 248, 8, 224, 31)
GUICtrlSetFont(-1, 20, 400, 0, "宋体")
$Label2 = GUICtrlCreateLabel("户名:", 32, 48, 63, 17)
GUICtrlSetFont(-1, 10, 400, 0, "宋体")
$Input = GUICtrlCreateInput("", 128, 48, 121, 21)
GUICtrlSetState(-1,$GUI_FOCUS)
$Label3 = GUICtrlCreateLabel("号码:", 288, 48, 69, 17)
GUICtrlSetFont(-1, 10, 400, 0, "宋体")
$Input = GUICtrlCreateInput("", 392, 48, 121, 21)
$Label4 = GUICtrlCreateLabel("品名:", 32, 96, 64, 17)
$Input = GUICtrlCreateCombo("", 128, 96, 121, 25, BitOR($CBS_DROPDOWN,$CBS_AUTOHSCROLL))
GUICtrlSetData(-1, "1|2|3|4|5|6|7|8|9|")
$Label5 = GUICtrlCreateLabel("单位:", 288, 96, 40, 17)
$Input = GUICtrlCreateCombo("", 392, 96, 121, 25, BitOR($CBS_DROPDOWN,$CBS_AUTOHSCROLL))
GUICtrlSetData(-1, "1|2|3|4|5|6|7|8|9")
$Label6 = GUICtrlCreateLabel("数量:", 32, 144, 40, 17)
$Input = GUICtrlCreateInput("", 128, 144, 121, 21,$ES_NUMBER)
$Label7 = GUICtrlCreateLabel("单价:", 288, 144, 40, 17)
$Input = GUICtrlCreateInput("", 392, 144, 121, 21,$ES_NUMBER)
$buton1 = GUICtrlCreateButton("确定",150, 244, 121, 45)
$buton2 = GUICtrlCreateButton("取消",310, 244, 121, 45)
GUICtrlSetOnEvent($buton1, "OKPressed")
GUICtrlSetOnEvent($buton2, "NoPressed")
GUISetState(@SW_SHOW)
While 1
Sleep(10)
WEnd
Func SEvents()
Select
Case @GUI_CtrlId = $GUI_EVENT_CLOSE
Exit
EndSelect
EndFunc
Func OnDummyEvents()
Switch @GUI_CtrlId
Case $iUP ;向上
Local $focusName=ControlGetFocus($hForm)
For $i=1 To 6
If $focusName ="Edit"&$i Then
If $i >2 Then GUICtrlSetState($Input[$i-2],$GUI_FOCUS)
ExitLoop
EndIf
Next
Case $iDOWN ;向下
Local $focusName=ControlGetFocus($hForm)
For $i=1 To 6
If $focusName ="Edit"&$i Then
If $i<5 Then GUICtrlSetState($Input[$i+2],$GUI_FOCUS)
ExitLoop
EndIf
Next
Case $iLEFT ;向左
Local $focusName=ControlGetFocus($hForm)
For $i=1 To 6
If $focusName ="Edit"&$i Then
If $i > 1 Then GUICtrlSetState($Input[$i-1],$GUI_FOCUS)
ExitLoop
EndIf
Next
Case $iRIGHT ;向右
Local $focusName=ControlGetFocus($hForm)
For $i=1 To 6
If $focusName ="Edit"&$i Then
If $i<6Then GUICtrlSetState($Input[$i+1],$GUI_FOCUS)
ExitLoop
EndIf
Next
EndSwitch
EndFunc
Func OKPressed()
exit
EndFunc ;==>OKPressed
Func NoPressed()
Exit
EndFunc
回复cashiba
用最简单的思路
chamlien 发表于 2017-4-14 15:16 http://www.autoitx.com/images/common/back.gif
这个方法也不错阿,跟虚拟控件一样的效果,利用了焦点的转移 8楼的代码怎样改正才能正常效果呢?
{:face (382):} 8楼是事件模式,好像改成消息模式就正常了,估计事件模式写法又问题.....
{:face (245):} 本帖最后由 kk_lee69 于 2017-4-20 10:54 编辑
回复 12# cashiba
8樓 使用 GUIRegisterMsg($WM_COMMAND, "WM_COMMAND")
即可解決
關鍵是 GUICtrlCreateDummy() 這個產生的控件不能使用 GUISetOnEvent 去註冊
請直接 使用 GUIRegisterMsg($WM_COMMAND, "WM_COMMAND") 回复 12# cashiba
用你原本的方法.................
#include <ButtonConstants.au3>
#include <ComboConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <Array.au3>
Opt("GUIOnEventMode", 1)
#Region ### START Koda GUI section ### Form=
$hForm = GUICreate("Form", 634, 376)
GUISetOnEvent($GUI_EVENT_CLOSE, "SEvents")
$iDumyu = GUICtrlCreateDummy()
GUICtrlSetOnEvent(-1, "Onu") ; ?理按???事件
$iDumyd = GUICtrlCreateDummy()
GUICtrlSetOnEvent(-1, "Ond") ; ?理按???事件
$iDumyl = GUICtrlCreateDummy()
GUICtrlSetOnEvent(-1, "Onl") ; ?理按???事件
$iDumyr = GUICtrlCreateDummy()
GUICtrlSetOnEvent(-1, "Onr") ; ?理按???事件
Dim $Quickeys = [["{UP}",$iDumyu],["{DOWN}",$iDumyd],["{LEFT}",$iDumyl],["{RIGHT}",$iDumyr]]
GUISetAccelerators($Quickeys,$hForm)
$Label1 = GUICtrlCreateLabel("?据?入窗口", 248, 8, 224, 31)
GUICtrlSetFont(-1, 20, 400, 0, "宋体")
$Label2 = GUICtrlCreateLabel("?名:", 32, 48, 63, 17)
GUICtrlSetFont(-1, 10, 400, 0, "宋体")
$Input1 = GUICtrlCreateInput("", 128, 48, 121, 21)
$Label3 = GUICtrlCreateLabel("??:", 288, 48, 69, 17)
GUICtrlSetFont(-1, 10, 400, 0, "宋体")
$Input2 = GUICtrlCreateInput("", 392, 48, 121, 21)
$Label4 = GUICtrlCreateLabel("品名:", 32, 96, 64, 17)
$combo1 = GUICtrlCreateCombo("", 128, 96, 121, 25, BitOR($CBS_DROPDOWN,$CBS_AUTOHSCROLL))
GUICtrlSetData(-1, "1|2|3|4|5|6|7|8|9|")
$Label5 = GUICtrlCreateLabel("?位:", 288, 96, 40, 17)
$combo2 = GUICtrlCreateCombo("", 392, 96, 121, 25, BitOR($CBS_DROPDOWN,$CBS_AUTOHSCROLL))
GUICtrlSetData(-1, "1|2|3|4|5|6|7|8|9")
$Label6 = GUICtrlCreateLabel("?量:", 32, 144, 40, 17)
$Input3 = GUICtrlCreateInput("", 128, 144, 121, 21,$ES_NUMBER)
$Label7 = GUICtrlCreateLabel("?价:", 288, 144, 40, 17)
$Input4 = GUICtrlCreateInput("", 392, 144, 121, 21,$ES_NUMBER)
$buton1 = GUICtrlCreateButton("确定",150, 244, 121, 45)
$buton2 = GUICtrlCreateButton("取消",310, 244, 121, 45)
GUICtrlSetOnEvent($buton1, "OKPressed")
GUICtrlSetOnEvent($buton2, "NoPressed")
GUISetState(@SW_SHOW)
While 1
Sleep(10)
WEnd
Func SEvents()
Select
Case @GUI_CtrlId = $GUI_EVENT_CLOSE
Exit
EndSelect
EndFunc
Func OKPressed()
exit
EndFunc ;==>OKPressed
Func NoPressed()
Exit
EndFunc
Func Onu()
Send("+{TAB 2}")
EndFunc
Func Ond()
Send("{TAB 2}")
EndFunc
Func Onl()
Send("+{TAB}")
EndFunc
Func Onr()
Send("{TAB}")
EndFunc 回复 8# cashiba
#include <ButtonConstants.au3>
#include <ComboConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <Array.au3>
Opt("GUIOnEventMode", 1)
#Region ### START Koda GUI section ### Form=
$hForm = GUICreate("Form", 634, 376)
GUISetOnEvent($GUI_EVENT_CLOSE, "SEvents")
$iDumyu = GUICtrlCreateDummy()
$iDumyd = GUICtrlCreateDummy()
$iDumyl = GUICtrlCreateDummy()
$iDumyr = GUICtrlCreateDummy()
Dim $Quickeys = [["{UP}",$iDumyu],["{DOWN}",$iDumyd],["{LEFT}",$iDumyl],["{RIGHT}",$iDumyr]]
GUISetAccelerators($Quickeys,$hForm)
for $i=0 to 3
GUICtrlSendToDummy($Quickeys[$i], 1)
GUICtrlSetOnEvent($Quickeys[$i], "OnDummyEvents")
Next
$Label1 = GUICtrlCreateLabel("資料錄入視窗", 248, 8, 224, 31)
GUICtrlSetFont(-1, 20, 400, 0, "宋體")
$Label2 = GUICtrlCreateLabel("戶名:", 32, 48, 63, 17)
GUICtrlSetFont(-1, 10, 400, 0, "宋體")
$Input1 = GUICtrlCreateInput("", 128, 48, 121, 21)
$Label3 = GUICtrlCreateLabel("號碼:", 288, 48, 69, 17)
GUICtrlSetFont(-1, 10, 400, 0, "宋體")
$Input2 = GUICtrlCreateInput("", 392, 48, 121, 21)
$Label4 = GUICtrlCreateLabel("品名:", 32, 96, 64, 17)
$combo1 = GUICtrlCreateCombo("", 128, 96, 121, 25, BitOR($CBS_DROPDOWN,$CBS_AUTOHSCROLL))
GUICtrlSetData(-1, "1|2|3|4|5|6|7|8|9|")
$Label5 = GUICtrlCreateLabel("單位:", 288, 96, 40, 17)
$combo2 = GUICtrlCreateCombo("", 392, 96, 121, 25, BitOR($CBS_DROPDOWN,$CBS_AUTOHSCROLL))
GUICtrlSetData(-1, "1|2|3|4|5|6|7|8|9")
$Label6 = GUICtrlCreateLabel("數量:", 32, 144, 40, 17)
$Input3 = GUICtrlCreateInput("", 128, 144, 121, 21,$ES_NUMBER)
$Label7 = GUICtrlCreateLabel("單價:", 288, 144, 40, 17)
$Input4 = GUICtrlCreateInput("", 392, 144, 121, 21,$ES_NUMBER)
$buton1 = GUICtrlCreateButton("確定",150, 244, 121, 45)
$buton2 = GUICtrlCreateButton("取消",310, 244, 121, 45)
GUICtrlSetOnEvent($buton1, "OKPressed")
GUICtrlSetOnEvent($buton2, "NoPressed")
GUISetState(@SW_SHOW)
While 1
Sleep(10)
WEnd
Func SEvents()
Select
Case @GUI_CtrlId = $GUI_EVENT_CLOSE
Exit
EndSelect
EndFunc
Func OnDummyEvents()
Switch @GUI_CtrlId
Case $iDumyu
Send("+{TAB 2}")
Case $iDumyd
Send("{TAB 2}")
Case $iDumyl
Send("+{TAB}")
Case $iDumyr
Send("{TAB}")
EndSwitch
EndFunc
Func OKPressed()
exit
EndFunc ;==>OKPressed
Func NoPressed()
Exit
EndFunc
页:
[1]
2