Jump to content
Skysnake

[solved] GUISetAccelerators(0) ; Remove accelerator link

Recommended Posts

Skysnake

Hi All

Question, the Help file contains this:

Quote

They are only active when the GUI specified in the function is active

So, is it necessary to put 

GUISetAccelerators(0) ; Remove accelerator link

in the GUI?  Once the GUI is deleted, the Accelerators are gone...?

Enter like tab discussion contains this item.  Is it essential?

Edited by Skysnake

Skysnake

Why is the snake in the sky?

Share this post


Link to post
Share on other sites
Melba23

Skysnake,

Once you delete the GUI any Accelerator keys linked to that GUI are also deleted.

In the script to which you linked it was necessary to remove the accelerator key linkage while the script was running in order to send the native key to the GUI, so I used:

GUISetAccelerators(0)

to do this and then promptly reset them once the native key had been sent. This is a similar situation to when you need to unbind a HotKey to use the native key within the called function.

I hope that is clear - please ask again if you have any questions.

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites
Skysnake

@Melba23 I do understand.  The implications for the GUI are not clear yet, but now I understand why and what to look for.  Thank you


Skysnake

Why is the snake in the sky?

Share this post


Link to post
Share on other sites

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

  • Similar Content

    • therks
      By therks
      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. 😅
    • AndyS19
      By AndyS19
      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  
    • John C.
      By John C.
      ;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)
       
    • vindicta
      By vindicta
      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.
    • kcvinu
      By kcvinu
      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.
×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.