jamer 发表于 2011-12-3 01:47:55

如果让一个输入框响应键盘而不响应鼠标改变

本帖最后由 jamer 于 2011-12-3 01:50 编辑

可能题目讲的不是很严谨,我的意思是这样的,一个输入框,当我输入完成后,按回车,自动调用某函数(我额外弄个了按钮,目的就是为了表现输入框中按回车和点击按钮的效果一样)
#include <GUIConstantsEx.au3>

$Form1_1 = GUICreate("Form1", 298, 100, 450, 339)
$Input1 = GUICtrlCreateInput("password", 20, 16, 137, 21)
$label1 = GUICtrlCreateLabel("原文",20,50,147,21)
$Button2 = GUICtrlCreateButton("显示", 240, 16, 49, 73)
GUISetState(@SW_SHOW)

While 1
      $nMsg = GUIGetMsg()
      Switch $nMsg
                Case $GUI_EVENT_CLOSE
                        Exit
        Case $Button2 Or $label1
                 GUICtrlSetData($label1,GUICtrlRead($Input1))
      EndSwitch
WEnd
我的愿意是,输入框输入完成后,按回车,输入框内容输出到标签上
但是上面这个代码也响应鼠标改变,即输入完文本后,移动鼠标,输入框内容也会输出到标签上,我想禁止这个响应,只在键盘回车时会输出内容(如果能检测输入框内容改变 然后输出内容就更好了)
Au3Chm函数询捕 实现了这个功能,想知道怎么实现的。。
求达人

风行者 发表于 2011-12-3 02:02:13

#include <GUIConstantsEx.au3>

$Form1_1 = GUICreate("Form1", 298, 100, 450, 339)
$Input1 = GUICtrlCreateInput("password", 20, 16, 137, 21)
$label1 = GUICtrlCreateLabel("原文",20,50,147,21)
$Button2 = GUICtrlCreateButton("显示", 240, 16, 49, 73)
GUISetState(@SW_SHOW)

While 1
      $nMsg = GUIGetMsg()
      Switch $nMsg
                Case $GUI_EVENT_CLOSE
                        Exit
      Case $Button2,$Input1
               GUICtrlSetData($label1,GUICtrlRead($Input1))
      EndSwitch
WEnd

jamer 发表于 2011-12-3 02:15:52

。。这么简单啊。。
那再问一下case里面 逗号 和 OR的区别在那里呢?

3mile 发表于 2011-12-3 09:37:12

回复 3# jamer
#include <GUIConstantsEx.au3>

$Form1_1 = GUICreate("Form1", 298, 100, 450, 339)
$Input1 = GUICtrlCreateInput("password", 20, 16, 137, 21)
$label1 = GUICtrlCreateLabel("原文", 20, 50, 147, 21)
$Button2 = GUICtrlCreateButton("显示", 240, 16, 49, 73)
$Dummy = GUICtrlCreateDummy()
GUISetState(@SW_SHOW)

Local $Key = [["{Enter}", $Dummy]]
GUISetAccelerators($Key)

While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
                Case $GUI_EVENT_CLOSE
                        Exit
                Case $Button2
                        GUICtrlSetData($label1, GUICtrlRead($Input1))
                Case $Dummy
                        Local $aResult = DllCall("user32.dll", "hwnd", "GetFocus")
                        If $aResult = GUICtrlGetHandle($Input1) Then
                                GUICtrlSetData($label1, GUICtrlRead($Input1))
                        EndIf
        EndSwitch
WEnd
页: [1]
查看完整版本: 如果让一个输入框响应键盘而不响应鼠标改变