Jump to content

[Edit widget] Tell what keys were hit?


Go to solution Solved by Nine,

Recommended Posts

Posted

Hello,

When using an Edit widget, I need to tell if the user hit CTRL+F (to launch a new search) or F3 (to resume searching, in case the same string occurs more than once).

GUICtrlCreateDummy() + GUISetAccelerators() does the job, but I was wondering if there's a way to go through the Edit widget instead and tell what keys were hit.

#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 689, 540, 286, 121)
$Edit1 = GUICtrlCreateEdit("", 0, 0, 688, 539,BitOR($ES_WANTRETURN, $ES_MULTILINE, $WS_VSCROLL, $ES_AUTOVSCROLL,$ES_READONLY))

;Two IDs to tell which keys were pressed: CTRL+F or F3?
Local $IdSearch = GUICtrlCreateDummy()
Local $IdF3 = GUICtrlCreateDummy()
;Local $aAccelKeys[2][2] = [["^f", $Edit1],["{F3}", $Edit1]]
Local $aAccelKeys[2][2] = [["^f", $IdSearch],["{F3}", $IdF3]]
GUISetAccelerators($aAccelKeys)

GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While True
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $IdSearch
            MsgBox($MB_OK, "$IdSearch", "$IdSearch")
        Case $IdF3
            MsgBox($MB_OK, "$IdF3", "$IdF3")

        Case $Edit1 ;How to check if user pressed CTRL+F or F3?
            ExitLoop
            ;Case CTRL+F
            Local $sSearch = InputBox ( "Search", "Search for")
            if not @error Then
                SearchInEdit ($Edit1,$sSearch,$searchInEditStartingPos)
            EndIf

            ;Case F3: Get current location, and search further

        Case $GUI_EVENT_CLOSE
            Exit

    EndSwitch
WEnd

Thank you.

  • Solution
Posted

You could create a callback to the edit control, intercept WM_KEYDOWN, decode the scan code to find ^F and F3, and then send a message to a GUI dummy control...

But I think it is rather complicated solution, for nothing.  Better stick with the accelerator keys.

Posted (edited)
#include <EditConstants.au3>
#include <WindowsConstants.au3>
#include <MsgBoxConstants.au3>
#include <GUIConstantsEx.au3>
#include <Misc.au3>

#Region ### START Koda GUI section ### Form=
Global $Form1 = GUICreate("Form1", 689, 540, 286, 121)
Global $Edit1 = GUICtrlCreateEdit("123 123 123", 0, 0, 688, 539, BitOR($ES_WANTRETURN, $ES_MULTILINE, $WS_VSCROLL, $ES_AUTOVSCROLL, $ES_READONLY))
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

Global $hDLL = DllOpen("user32.dll")
Global $sControl, $sSearch, $nMsg

While True
    $nMsg = GUIGetMsg()
    Switch $nMsg

        Case $GUI_EVENT_CLOSE
            GoToExit()
    EndSwitch

    $sControl = ControlGetFocus($Form1)
    If $sControl = "Edit1" Then
        If _IsPressed("11", $hDLL) And _IsPressed("46", $hDLL) Then  ;11 = CTRL key ;46 = F key
            ConsoleWrite("_IsPressed - CTRL + F Key was pressed in $sControl:" & $sControl & @CRLF)

        ElseIf _IsPressed("72", $hDLL) Then           ;72 = F3 key
            ConsoleWrite("_IsPressed - F3 Key was pressed in $sControl:" & $sControl & @CRLF)

        EndIf
    EndIf

WEnd

GoToExit()
;-------------------------------------------------------------------------------
Func GoToExit()    ; exit
    DllClose($hDLL)
    Exit
EndFunc   ;==>GoToExit
;-------------------------------------------------------------------------------

if it helps.

Edited by ioa747

I know that I know nothing

Posted (edited)
3 minutes ago, littlebigman said:

but didn't know how to use it to check for CTRL + F.

it's in the example

2 hours ago, ioa747 said:
If _IsPressed("11", $hDLL) And _IsPressed("46", $hDLL) Then  ;11 = CTRL key ;46 = F key

 

Edited by ioa747

I know that I know nothing

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...