找回密码
 加入
搜索
查看: 6007|回复: 15

[GUI管理] GUI界面上如何用方向键箭头控制光标自由移动[已解决]

  [复制链接]
发表于 2017-3-27 00:52:12 | 显示全部楼层 |阅读模式
本帖最后由 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定向移动光标。但是总不如用四向箭头自由移动光标。
请问大虾们如何用键盘上下左右方向键控制光标在控件间自由移动涅?
发表于 2017-3-29 13:35:17 | 显示全部楼层
本帖最后由 afan 于 2017-3-29 13:42 编辑

发帖不要有“发\票”这些敏感词
如果编辑就去掉这些,不然再审核我就直接删了。

GUISetAccelerators 设置方向键的快捷方式 即可
 楼主| 发表于 2017-3-29 13:59:29 | 显示全部楼层
原来是fa\piao的原因.....
代码是借用当时正在看的一个实例里的框架,又过了两天,对代码里面的文本词语没什么印象...
还以为是自己的描述语言有fa或piao什么的情况。现在明白了....
A大已经指明了解决办法,那也算解决啦
剩下的就是学习GUISetAccelerators函数了。
发表于 2017-3-30 00:01:40 | 显示全部楼层
没办法实现的
发表于 2017-3-31 09:17:32 | 显示全部楼层
学习了   还不清楚有这个 GUISetAccelerators
发表于 2017-3-31 12:43:07 | 显示全部楼层
感谢分享。
发表于 2017-3-31 23:55:07 | 显示全部楼层
用模拟按键
 楼主| 发表于 2017-4-14 13:07:58 | 显示全部楼层
本帖最后由 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[4][2] = [["{UP}",$iDumyu],["{DOWN}",$iDumyd],["{LEFT}",$iDumyl],["{RIGHT}",$iDumyr]]
GUISetAccelerators($Quickeys,$hForm)

for $i=0 to 3
        GUICtrlSendToDummy($Quickeys[$i][1], 1)
        GUISetOnEvent($Quickeys[$i][1], "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
还差一点就成功了.....
不知哪里没写对
路过的大侠请指点哈
我等新手青木们可以顺便了解一下虚拟控件、快捷键以及事件模式等
发表于 2017-4-14 15:16:53 | 显示全部楼层
回复 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[7], $hHandle[7]
#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[4][2] = [["{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[1] = GUICtrlCreateInput("", 128, 48, 121, 21)
GUICtrlSetState(-1,$GUI_FOCUS)
$Label3 = GUICtrlCreateLabel("号码:", 288, 48, 69, 17)
GUICtrlSetFont(-1, 10, 400, 0, "宋体")
$Input[2] = GUICtrlCreateInput("", 392, 48, 121, 21)


$Label4 = GUICtrlCreateLabel("品名:", 32, 96, 64, 17)
$Input[3] = 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[4] = 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[5] = GUICtrlCreateInput("", 128, 144, 121, 21,$ES_NUMBER)

$Label7 = GUICtrlCreateLabel("单价:", 288, 144, 40, 17)
$Input[6] = 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<6  Then GUICtrlSetState($Input[$i+1],$GUI_FOCUS)
                                        ExitLoop
                                EndIf
                        Next
    EndSwitch
EndFunc

Func OKPressed()
     exit
EndFunc   ;==>OKPressed

Func NoPressed()
        Exit
EndFunc

评分

参与人数 1金钱 +19 收起 理由
cashiba + 19

查看全部评分

 楼主| 发表于 2017-4-14 21:02:51 | 显示全部楼层
回复  cashiba
用最简单的思路
chamlien 发表于 2017-4-14 15:16

这个方法也不错阿,跟虚拟控件一样的效果,利用了焦点的转移
 楼主| 发表于 2017-4-14 21:07:25 | 显示全部楼层
8楼的代码怎样改正才能正常效果呢?
 楼主| 发表于 2017-4-19 12:51:16 | 显示全部楼层
8楼是事件模式,好像改成消息模式就正常了,估计事件模式写法又问题.....
发表于 2017-4-20 10:47:54 | 显示全部楼层
本帖最后由 kk_lee69 于 2017-4-20 10:54 编辑

回复 12# cashiba

8樓 使用      GUIRegisterMsg($WM_COMMAND, "WM_COMMAND")

即可解決

關鍵是 GUICtrlCreateDummy() 這個產生的控件  不能使用 GUISetOnEvent 去註冊

請直接 使用 GUIRegisterMsg($WM_COMMAND, "WM_COMMAND")
发表于 2017-4-20 13:43:17 | 显示全部楼层
回复 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[4][2] = [["{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 

评分

参与人数 1金钱 +25 收起 理由
cashiba + 25

查看全部评分

发表于 2017-4-20 14:40:18 | 显示全部楼层
回复 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[4][2] = [["{UP}",$iDumyu],["{DOWN}",$iDumyd],["{LEFT}",$iDumyl],["{RIGHT}",$iDumyr]]
GUISetAccelerators($Quickeys,$hForm)

for $i=0 to 3
        GUICtrlSendToDummy($Quickeys[$i][1], 1)
        GUICtrlSetOnEvent($Quickeys[$i][1], "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金钱 +25 收起 理由
cashiba + 25

查看全部评分

您需要登录后才可以回帖 登录 | 加入

本版积分规则

QQ|手机版|小黑屋|AUTOIT CN ( 鲁ICP备19019924号-1 )谷歌 百度

GMT+8, 2024-11-22 11:19 , Processed in 0.147416 second(s), 24 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表