littlebigman Posted April 3, 2023 Posted April 3, 2023 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. expandcollapse popup#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. jackpaulene 1
Solution Nine Posted April 3, 2023 Solution Posted April 3, 2023 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. “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy
ioa747 Posted April 3, 2023 Posted April 3, 2023 (edited) expandcollapse popup#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 April 3, 2023 by ioa747 I know that I know nothing
littlebigman Posted April 3, 2023 Author Posted April 3, 2023 Good to know. I did play with _IsPressed, but didn't know how to use it to check for CTRL + F.
ioa747 Posted April 3, 2023 Posted April 3, 2023 (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 April 3, 2023 by ioa747 I know that I know nothing
littlebigman Posted April 3, 2023 Author Posted April 3, 2023 Yes. I meant that I already tried this before asking, and looked at GUICtrlCreateDummy() + GUISetAccelerators() instead.
Zedna Posted April 9, 2023 Posted April 9, 2023 (edited) Maybe HotKey control is what are looking for? https://learn.microsoft.com/en-us/windows/win32/controls/hot-key-controls On this forum there are some AU3 examples for this type of control ... Edited April 9, 2023 by Zedna Resources UDF ResourcesEx UDF AutoIt Forum Search
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now