找回密码
 加入
搜索
查看: 3282|回复: 10

[AU3基础] 敲键盘上的回车键模拟点击按钮功能该如何写(已解决)

  [复制链接]
发表于 2018-3-9 10:35:57 | 显示全部楼层 |阅读模式
本帖最后由 qsy666888 于 2018-4-1 13:54 编辑

不用鼠标点击$Button1 按钮,敲键盘上的回车键来指令$Button1 按钮功能'
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 310, 190)
$Button1 = GUICtrlCreateButton("回车键", 112, 56, 75, 25)
$Button2 = GUICtrlCreateButton("Button2", 112, 88, 75, 25)
$Button3 = GUICtrlCreateButton("Button3", 112, 120, 75, 25)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
                Case $GUI_EVENT_CLOSE
                        Exit
                Case $Button1
                        MsgBox(0,'','敲键盘上的回车键模拟点击$Button1 按钮功能')
        EndSwitch
WEnd
发表于 2018-3-9 10:43:30 | 显示全部楼层
$Button1 = GUICtrlCreateButton("回车键", 112, 56, 75, 25,$BS_DEFPUSHBUTTON)

焦点在此按钮上
 楼主| 发表于 2018-3-9 11:01:00 | 显示全部楼层
回复 2# 229989799
不是你那个意思,我是想执行$Button2按钮 或者$Button3按钮操作后,按一下回车键就执行了$Button1按钮的功能
发表于 2018-3-9 11:04:46 | 显示全部楼层
论坛有很多例子啊~·  搜索一下
发表于 2018-3-9 11:09:18 | 显示全部楼层
回复 3# qsy666888


    http://www.autoit3.cn/thread-56537-1-2.html

我就记得是你提问的来着,果不其然~
发表于 2018-3-9 11:15:00 | 显示全部楼层

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 310, 190)
$Button1 = GUICtrlCreateButton("回车键", 112, 56, 75, 25,$BS_DEFPUSHBUTTON)
$Button2 = GUICtrlCreateButton("Button2", 112, 88, 75, 25)
$Button3 = GUICtrlCreateButton("Button3", 112, 120, 75, 25)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
                Case $GUI_EVENT_CLOSE
                        Exit
                Case $Button1
                        MsgBox(0,'','敲键盘上的回车键模拟点击$Button1 按钮功能')
                                                GUICtrlSetState($Button1,256)
                                Case $Button2
                        MsgBox(0,'','按钮2')
                                                GUICtrlSetState($Button1,256)
                Case $Button3
                        MsgBox(0,'','按钮3')
                                                GUICtrlSetState($Button1,256)
        EndSwitch
WEnd
发表于 2018-3-9 11:16:32 | 显示全部楼层
本帖最后由 austere 于 2018-3-9 11:18 编辑

回复 1# qsy666888
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 310, 190)
$Button1 = GUICtrlCreateButton("回车键", 112, 56, 75, 25)


Dim $123[1][2] = [["{ENTER}", $Button1]]
GUISetAccelerators($123)


$Button2 = GUICtrlCreateButton("Button2", 112, 88, 75, 25)
$Button3 = GUICtrlCreateButton("Button3", 112, 120, 75, 25)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
                Case $GUI_EVENT_CLOSE
                        Exit
                Case $Button1
                        MsgBox(0, '', '敲键盘上的回车键模拟点击$Button1 按钮功能')
        EndSwitch
WEnd
 楼主| 发表于 2018-3-9 16:55:00 | 显示全部楼层
回复 7# austere

谢谢兄弟,让兄弟笑了,上一个帖子是让按钮建立退格功能,这次是让按钮跟键盘的回车键相联,谢谢兄弟了
发表于 2018-3-9 16:59:19 | 显示全部楼层
回复 8# qsy666888


    实际上是一样的~  你用我发的这个,也适合你退格那个~    多搜索一下就好了
发表于 2018-3-13 01:03:12 | 显示全部楼层
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 310, 190)
$Button1 = GUICtrlCreateButton("回车键", 112, 56, 75, 25)
$Button2 = GUICtrlCreateButton("Button2", 112, 88, 75, 25)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###


While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
                Case $GUI_EVENT_CLOSE
                        Exit
                                Case $Button1
                                        _fc_1()

                                Case $Button2
                                        HotKeySet("{enter}",'_fc_1')
                                        ConsoleWrite(2)

        EndSwitch
WEnd
        
Func _fc_1()
        MsgBox(0,'','敲键盘上的回车键模拟点击$Button1 按钮功能')
EndFunc


        
 楼主| 发表于 2018-3-13 01:35:24 | 显示全部楼层
回复 10# fenhanxue

HotKeySet这个代码问题多,运行这个代码就不能操作其他程序,
您需要登录后才可以回帖 登录 | 加入

本版积分规则

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

GMT+8, 2024-9-28 09:33 , Processed in 0.130724 second(s), 20 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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