Search the Community
Showing results for tags 'guisetaccelerators'.
-
Hi I am trying to set Accelerator keys from an array. I select the KEY and CONTROL from a SQLite table, the Array looks like that generated for the Helpfile, but I can't get the CONTROLS to resolve... I though about Assign & Eval, but not sure if that's a step in the right direction. IsDeclared shows that the $var exists in Local Scope -1. Local $Main = GUICreate("Custom MsgBox", 225, 80) GUICtrlCreateLabel("Please select a button.", 10, 10) Local $idButton_Yes = GUICtrlCreateButton("Yes", 10, 50, 65, 25) Local $idButton_No = GUICtrlCreateButton("No", 80, 50, 65, 25) Local $idButton_Exit = GUICtrlCreateButton("Exit", 150, 50, 65, 25) Local $query, $aResult, $iRows, $iColumns $query = "" ;reset $query = "Select hotkey_key, hotkey_ctrl from mytable where mykeys = 'hotkey' ; " ; ; Query $iRval = _SQLite_GetTable2d($sqliteDb, $query, $aResult, $iRows, $iColumns) If $iRval = $SQLITE_OK Then Local $sizeofHotkeys = UBound($aResult) - 1 ConsoleWrite("$sizeofHotkeys " & $sizeofHotkeys & @CRLF) If $sizeofHotkeys > 0 Then Local $main__aAccelKeys[$sizeofHotkeys][2] For $i = 0 To $sizeofHotkeys - 1 $j = $i + 1 ; replace friendly text with code -- ! alt + Shift ^ Ctrl # Windows $aResult[$j][0] = StringReplace($aResult[$j][0], "Alt", "!") $aResult[$j][0] = StringReplace($aResult[$j][0], "Shift", "+") $aResult[$j][0] = StringReplace($aResult[$j][0], "Ctrl", "^") $main__aAccelKeys[$i][0] = $aResult[$j][0] ;--- $main__aAccelKeys[$i][1] = $aResult[$j][1] ;--- Next ;~ Row|Col 0|Col 1 ;~ Row 0|F2|$idButton_Yes ;~ Row 1|F3|$idButton_No _DebugArrayDisplay($main__aAccelKeys) Local $rv = GUISetAccelerators($main__aAccelKeys, $Main) GUISetState(@SW_SHOW) ; Display the GUI. Please note that this is a modified Helpfile example. The Helpfile specifies (a) WinHandle and (b) last Gui created. --> the example uses a control not a WinHandle and (b) what happens with ChildGuis? Also, the HelpFile specifies lower case, yet the examples show "{F1}" upper case? Also, is there a way to check the result of the GuiSetAccelerator function? Note, if I add these to lines after the FOR loop, then the F1 works, and the DebugArrayDisplays shows control 4... not it's name... So I am in the right place, but my $vars names do not convert to their control numbers in the GUI Next $main__aAccelKeys[$sizeofHotkeys - 1][0] = "{F1}" ; -- -- use the extra row for the F1 $main__aAccelKeys[$sizeofHotkeys - 1][1] = $ChmHLP ;--- Skysnake
- 3 replies
-
- guisetaccelerators
- sqlite
-
(and 1 more)
Tagged with:
-
So I'm working on an application and I've hot keyed all the numbers, and for some reason this particular combination doesn't work. All the other numbers with Ctrl+Shift work fine, and all other combinations of modifiers work with 0. Has anyone else encountered this? It's very strange. Guicreate('', 300, 300) $button = GUICtrlCreateButton('Button', 0, 0) Dim $accel = [ [ '^+0', $button ] ] GUIsetaccelerators($accel) Do $gm = guigetmsg() If $gm = $button then msgbox(0,'','test') Until $gm = - 3 Sorry for the ugly code, i typed this up on my phone. 😅
-
I have a script that traps ^A and ^C accelerator keys via the GUISetAccelerators() function, and in the key handlers, I check to see if the focus is on the control that I want the keys to operate on. However, when I see that I'm not on that control, I want to pass the ^C and ^A back to the system so I can copy and past data on other controls. Here is my test script. I have it applying ^A and ^C only to the ListView control. When I put focus on the Input control, I want to be able to copy and paste normally. Opt("GUICloseOnESC", 1) ; ESC does not close the GUI Opt("GUIOnEventMode", 1) ; Change to OnEvent mode Opt('MustDeclareVars', 1) OnAutoItExitRegister("ExitStageLeft") #include <Array.au3> #include <GuiListBox.au3> #include <GUIConstantsEx.au3> #include <ListBoxConstants.au3> #include <WindowsConstants.au3> #include <GuiListView.au3> Global $hGUI, $iInput, $iList, $hInput, $hList _Main() Func _Main() Local $str, $parts $hGUI = GUICreate("", 250, 500) $iInput = GUICtrlCreateInput("2", 90, 5, 50, 20) $hInput = GUICtrlGetHandle($iInput) $iList = GUICtrlCreateListView("First Column ", 5, 30, 240, 470, $LBS_EXTENDEDSEL) $hList = GUICtrlGetHandle($iList) For $ndx = 1 To 100 $str = StringFormat("%s ABC", $ndx) Local $ret = _GUICtrlListView_AddItem($hList, $str) Next setupSpecialKeysHandlers() GUISetOnEvent($GUI_EVENT_CLOSE, "ExitStageLeft") GUISetState(@SW_SHOW) While (1) Sleep(250) WEnd EndFunc ;==>_Main Func ExitStageLeft() Exit (1) EndFunc ;==>ExitStageLeft Func setupSpecialKeysHandlers() Local $aAccelKeys[1][2] Local $ar, $parts, $key, $handler, $id ; Create a table of Special keys and their handlers $ar = StringSplit("", "") _ArrayAdd($ar, "{ENTER} - handle_ENTER_key ") _ArrayAdd($ar, "^a - handle_CTRL_A_key ") _ArrayAdd($ar, "^c - handle_CTRL_C_key ") ReDim $aAccelKeys[UBound($ar) - 1][2] ; Now, create $aAccelKeys array with the table data. ; For each entry, create a Dummy GUI and associate its ; ID with the special key. For $ndx = 1 To UBound($ar) - 1 $parts = StringSplit($ar[$ndx], "-", 2) $key = StringStripWS($parts[0], 8) $handler = StringStripWS($parts[1], 8) $id = GUICtrlCreateDummy() $aAccelKeys[$ndx - 1][0] = $key $aAccelKeys[$ndx - 1][1] = $id GUICtrlSetOnEvent($id, $handler) Next ; Dump the contents of the $aAccelKeys array For $ndx = 0 To UBound($aAccelKeys) - 1 logMsg("$aAccelKeys" _ & " [" & $ndx & "][0] = " & StringFormat("%-8s", $aAccelKeys[$ndx][0]) _ & " [" & $ndx & "][1] = " & $aAccelKeys[$ndx][1]) Next GUISetAccelerators($aAccelKeys) ; Setup the Special keys hooks EndFunc ;==>setupSpecialKeysHandlers Func logMsg($msg, $lnum = @ScriptLineNumber) ConsoleWrite("+++:" & $lnum & ": " & $msg & @CRLF) EndFunc ;==>logMsg Func handle_ENTER_key() logMsg("+++: handle_ENTER_key() entered") EndFunc ;==>handle_ENTER_key Func handle_CTRL_A_key() logMsg("+++: handle_CTRL_A_key() entered") If (Not isCtrlFocused($hList)) Then Return selectAllGLVItems() EndFunc ;==>handle_CTRL_A_key Func handle_CTRL_C_key() logMsg("+++: handle_CTRL_C_key() entered") If (isCtrlFocused($hList)) Then extractSelListViewGamesToClip() Else EndIf EndFunc ;==>handle_CTRL_C_key Func isCtrlFocused($hWnd) Local $hCtrl $hCtrl = ControlGetHandle($hGUI, "", ControlGetFocus($hGUI)) Return ($hWnd = $hCtrl) ? True : False EndFunc ;==>isCtrlFocused Func selectAllGLVItems() Local $hWnd = $hList, $iIndex For $iIndex = 0 To _GUICtrlListView_GetItemCount($hWnd) _GUICtrlListView_SetItemSelected($hWnd, $iIndex) Next EndFunc ;==>selectAllGLVItems Func extractSelListViewGamesToClip() Local $hWnd = $hList Local $iIndex, $item, $str, $sep = "" $str = "" For $iIndex = 0 To _GUICtrlListView_GetItemCount($hWnd) If (_GUICtrlListView_GetItemSelected($hWnd, $iIndex)) Then $item = _GUICtrlListView_GetItemText($hWnd, $iIndex) $str &= $sep & $item $sep = @CRLF EndIf Next ClipPut($str) logMsg("Copied " & StringLen($str) & " bytes to the Clipboard:" & @CRLF & $str) EndFunc ;==>extractSelListViewGamesToClip
-
;Adding $BS_DEFPUSHBUTTON doesn't work $idCopy_Data = GUICtrlCreateButton("Copy Data Only", $iButtonWidth_2, $aiGUISize[1] - $iButtonMargin, $iButtonWidth_2, 20, $BS_DEFPUSHBUTTON) ;Adding these two lines doesn't work either Local $aAccelKeys[2][2] = [["{enter}", $idCopy_Data], ["^{enter}", $idCopy_ID]] GUISetAccelerators($aAccelKeys)
-
Hello everyone, I am trying to setup a GUI accelerator to close the utility as soon as esc is pressed. It works fine with hotkey but I want to make sure that the utility only exits if its window was active when esc was pressed. My utility has 2 buttons, Backup and Restore. The exit function checks if the button clicked was Backup or Restore and then displays an error message accordingly. If pressed backup, $button = 1 if pressed restore, $button = 2 the value of $button is set inside backup() or restore() functions Opt("GUIOnEventMode", 1) Opt("GUICoordMode", 1) $Form1 = GUICreate("Form1", 419, 124, 238, 194, $WS_DLGFRAME) $B_backup = GUICtrlCreateButton("Backup", 48, 40, 145, 41) $B_restore = GUICtrlCreateButton("Restore", 224, 40, 145, 41) ;================ > HotKeySet('{ESC}', "terminate") GUICtrlSetOnEvent($B_backup, "Backup") GUICtrlSetOnEvent($B_restore, "Restore") GUISetState(@SW_SHOW) Dim $accelKey[1][2] = [["{ESC}", terminate()]] GUISetAccelerators($accelKey) While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit EndSwitch WEnd Exit function: func terminate() Do $msg = GUIGetMsg() Until $msg <> 0 While 1 If $button = 1 Then ProcessClose("robocopy.exe") MsgBox(16, "Abort!", "Backup Aborted!") exit ElseIf $button = 2 Then ProcessClose("robocopy.exe") MsgBox(16, "Abort!", "Restore Aborted!") exit Else While 1 For $i = 3 To 1 Step -1 SplashTextOn("Closing Utility...", $i, 130, 54, -1, -1, 0, "Calibri", "", 900) Sleep(1000) Next ExitLoop WEnd SplashOff() Exit Endif WEnd What am I doing wrong here? The utility closes as soon as it launches with Splash text.
- 6 replies
-
- accelerator
- hotkey
-
(and 1 more)
Tagged with:
-
Hi all, I know GUISetAccelerators() function is helpful to set a hotkey for my GUI. But which function should i use for setting a hotkey for a specific control only. Say, i have 3 Textboxes and a button in my form. I want to display a msg box when i press the enter key while keyboard focus is in the first textbox. When i used GUISetAccelerators function, it is firing the event regardless the focuds of the control.
-
I have a GUI with several input boxes and I want to trap the ENTER key so I can call handlers for each one. However, when I put in a HotKeySet() to trap the ENTER key, it traps it OK, but I also get traps when I press the ENTER key anywhere else on my desktop, no matter what GUI has focus, so I changed the code to use GUISetAccelerators(). I cannot see how to attach a handler for the ENTER key for each of my input controls. My real script uses event mode (Opt("GUIOnEventMode", 1)), so that's what I'm using in my test code. Here is my test code: #NoTrayIcon #Region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_UseUpx=n #AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** #include <GUIConstantsEx.au3> #include <StructureConstants.au3> OnAutoItExitRegister("ExitStageLeft") Opt("GUICloseOnESC", 1) Opt("GUIEventOptions", 1) Opt("GUIOnEventMode", 1) ;; <===== Opt("WinTitleMatchMode", 1) Opt('MustDeclareVars', 1) Global $hWnd_list1, $hWnd_input1, $hGUI, $sWinTitle Global $iID_list1, $iID_input1 _Main() Exit (1) Func _Main() $sWinTitle = "ENTER key trap test" $hGUI = GUICreate($sWinTitle, 500, 230) GUICtrlCreateButton("Test", 5, 5, 50, 25) $iID_input1 = GUICtrlCreateInput("input1", 70, 5, 100, 25) $hWnd_input1 = GUICtrlGetHandle($iID_input1) $iID_list1 = GUICtrlCreateEdit("list1", 10, 40, 475, 190) $hWnd_list1 = GUICtrlGetHandle($iID_list1) GUICtrlSetData($iID_list1, "abcdefghijklmnopqrstuvwxyz" & @CRLF, 1) ConsoleWrite("+++: $iID_list1 = " & $iID_list1 & @CRLF) ConsoleWrite("+++: $iID_input1 = " & $iID_input1 & @CRLF) GUISetState() GUICtrlSetOnEvent($iID_list1, "handle_List1") GUICtrlSetOnEvent($iID_input1, "handle_Input1") GUISetOnEvent($GUI_EVENT_CLOSE, 'ExitStageLeft') Local $aAccelKeys[2][2] $aAccelKeys[0][0] = "{ENTER}" $aAccelKeys[0][1] = $iID_input1 $aAccelKeys[1][0] = "{ENTER}" $aAccelKeys[1][1] = $iID_list1 GUISetAccelerators($aAccelKeys) While (1) Sleep(250) WEnd EndFunc ;==>_Main Func ExitStageLeft() Exit (0) EndFunc ;==>ExitStageLeft Func handle_Input1() ConsoleWrite("+++: handle_Input1() entered" & @CRLF) EndFunc ;==>handle_Input1 Func handle_List1() ConsoleWrite("+++: handle_List1() entered" & @CRLF) EndFunc ;==>handle_List1