Jump to content

GUISetAccelerators() needs mouse move to trigger


 Share

Recommended Posts

I have a working database application (using SQLite and Excel) and decided that I would speed up data entry by mapping a couple of keyboard keys to two of the GUI buttons so as cut down on mouse movement back and forth across the screen. I used the GUISetAccelerators() function to map the forward slash (\) and back slash (/) keys to a couple of button handles and this works OK except that the mouse has to move (even a pixel will do) after the accelerator key is pressed before the code will respond to the key press. I can press the key, nothing happens, wait 10 seconds, still nothing, move the mouse pointer and immediately the program responds to the key press.

Whilst the app is over 6000 lines of code and has taken me several months to develop (so well tested by now), this is the first time I have tried to use GUISetAccelerators(). What trick am I missing here?

I will post more code if anybody thinks this will help, but I thought that somebody might have come across this effect before (yet a search turned up nothing useful)

Thanks, Terry

Local $CTRL_Van_Save = GUICtrlCreateButton("SAVE" & @CRLF & "and" & @CRLF & "\/     NEXT     \/" & @CRLF & "( \ )", 1335, 375, 150, 100, $BS_MULTILINE )
 GUICtrlSetFont(-1, 11)
...


    ; Set GUIAccelerator for the SAVE & NEXT button
    Local $aAccelKeys[2][2] = [["\", $CTRL_Van_Save],["/", $CTRL_Work_But]]
    GUISetAccelerators($aAccelKeys)
 $Refresh = 1
 While 1
  $key = Get_Click()
  Switch ($key)
   Case $CTRL_Work_But
    If GUICtrlRead($CTRL_Work_But) = 0 Then
     GUICtrlSetData($CTRL_Work_But, $aDataIn[$index][12])
...

   Case $CTRL_Van_Save
    ;does DataIn array have correct lookup values from radio and Attention?
    $Prop_ID = $aDataIn[$index][0]
    $aDataIn[$index][2] = GUICtrlRead($CTRL_Van_Notes)
    $aDataIn[$index][2] = StringReplace($aDataIn[$index][2], "'", "''") ;escape any apostrophes
...

 

Edited by Melba23
Added code tags
Link to comment
Share on other sites

  • Moderators

TerryF,

Welcome to the AutoIt forums.

What is inside the Get_Click function? I would have expected to see a GUIGetMsg at that point and I wonder if that might be a possible problem.

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see 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

 

Link to comment
Share on other sites

Melba23,

Thanks for the welcome. I should have included the function, but it is straightforward:

Func Get_Click() ;get user input
 ;get user click or key press
 Local $msg

 Do
  $msg = GUIGetMsg()
 Until $msg <> 0
 Return $msg

EndFunc

I have just written a little test prog and this does not exhibit the same issue, it works fine, so it looks like it is something in my code that is causing the problem.

Local $CTRL_Screen = GUICreate("Test Screen", 450, 400, 275, 200, BitOR($WS_SYSMENU, $WS_CAPTION, $WS_SIZEBOX, $WS_MINIMIZEBOX, $WS_MAXIMIZEBOX), $WS_EX_APPWINDOW )
Local $CTRL_Van_Save = GUICtrlCreateButton("SAVE" & @CRLF & "and" & @CRLF & "\/     NEXT     \/" & @CRLF & "( \ )", 150, 100, 150, 100, $BS_MULTILINE )
GUICtrlSetFont(-1, 11)
Local $CTRL_Exit = GUICtrlCreateButton("EXIT", 150, 350, 150, 40 )
GUICtrlSetFont(-1, 11)
Local $CTRL_Count = GUICtrlCreateLabel("0", 200, 260, 50, 30)
GUICtrlSetFont(-1, 11)
Local $Count = 0
GUISetState(@SW_SHOW, $CTRL_Screen)



; Set GUIAccelerator for the SAVE & NEXT button
Local $aAccelKeys[1][2] = [["\", $CTRL_Van_Save]]
GUISetAccelerators($aAccelKeys)

While 1
 $key = Get_Click()
 Switch ($key)
  Case $CTRL_Van_Save
   $Count += 1
   GUICtrlSetData($CTRL_Count, $Count)
  Case $CTRL_Exit
   Exit
 Endswitch
Wend

Exit

Func Get_Click() ;get user input
 ;get user click or key press
 Local $msg
 Do
  $msg = GUIGetMsg()
 Until $msg <> 0
 Return $msg
EndFunc

Regards, Terry

Edited by Melba23
Added code tags
Link to comment
Share on other sites

  • Moderators

TerryF,

I have just written a little test prog and this does not exhibit the same issue, it works fine, so it looks like it is something in my code that is causing the problem

So did my test - so I can only agree with you.

M23

P.S.  When you post code please use Code tags - see here how to do it.  Then you get a scrolling box and syntax colouring as you can see above now I have added the tags.

 

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see 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

 

Link to comment
Share on other sites

M23,

Thanks for the response and advice. Further experimenting has fixed the issue, my original code calls the GetClick() function and then refreshes the screen by updating a lot of fields and only then gets to a Switch($key) statement where it uses the $key value provided by the GetClick() call to correctly process the user input. Because the $key variable held the user input during the screen processing I would not have expected any issue, and did not have any until now. However, moving the GetClick() call to immediately before the Switch($key) statement solves the problem. Perhaps something has changed within the Windows internals during the delay that was causing the issue?

; lots of screen update code
        $key = Get_Click()
        Switch ($key)

    ;works OK

;rather than:

        $key = Get_Click()
        If $Refresh > 0 Then    ;display the correct rows in each listview

            For $top = 1  to 12
                $ptr = ($index + $top - 13)
                If $ptr < 1 Then
                    GUICtrlSetData($a_h_Top[$top], " | | | | | | | | | | | | " )
                Else
                    $pay_type = " "
                    $pay_amt = Format2str($aDataIn[$ptr][9])
                    Switch $aDataIn[$ptr][10]
                        Case ""
                            $pay_type = " "
                        Case 0
                            $pay_type = " "
                        Case 1
                            $pay_type = "Cash"
                        Case 2
                            $pay_type = "Cheque"
                        Case 3
                            $pay_type = "Split"
                            $pay_amt = Format2str($aDataIn[$ptr][9] + $aDataIn[$ptr][15])
                    EndSwitch

                    $Flag = " "
                    If $aDataIn[$ptr][11] = 1 Then $Flag = " X"
                    $PrePay = ""
                    If $aDataIn[$ptr][20] < 0 Then $PrePay = " CR"
                    GUICtrlSetData($a_h_Top[$top], $aDataIn[$ptr][1] & "|" & $aDataIn[$ptr][2] & " |  " & $aDataIn[$ptr][3] & "|  " & $aDataIn[$ptr][4] & "|  " & $aDataIn[$ptr][5] & "|  " & $aDataIn[$ptr][6] & "|  £" & $aDataIn[$ptr][7] & "| ¦ |  " & $aDataIn[$ptr][8] & "|  " & $pay_amt & "|" & $pay_type & "|  " & $Flag & "| £" & $aDataIn[$ptr][20] & $PrePay)
                Endif

            Next
            For $btm = 1 to 12
                $ptr = ($index + $btm)
                If $ptr > $aDataIn[0][0] Then
                    GUICtrlSetData($a_h_Btm[$btm], " | | | | | | | | | | | | " )
                Else
                    $pay_type = " "
                    $pay_amt = Format2str($aDataIn[$ptr][9])
                    Switch $aDataIn[$ptr][10]
                        Case ""
                            $pay_type = " "
                        Case 0
                            $pay_type = " "
                        Case 1
                            $pay_type = "Cash"
                        Case 2
                            $pay_type = "Cheque"
                        Case 3
                            $pay_type = "Split"
                            $pay_amt = Format2str($aDataIn[$ptr][9] + $aDataIn[$ptr][15])
                    EndSwitch

                    $Flag = " "
                    If $aDataIn[$ptr][11] = 1 Then $Flag = " X"
                    $PrePay = ""
                    If $aDataIn[$ptr][20] < 0 Then $PrePay = " CR"
                    GUICtrlSetData($a_h_Btm[$btm], $aDataIn[$ptr][1] & "|" & $aDataIn[$ptr][2] & " |  " & $aDataIn[$ptr][3] & "|  " & $aDataIn[$ptr][4] & "|  " & $aDataIn[$ptr][5] & "|  " & $aDataIn[$ptr][6] & "|  £" & $aDataIn[$ptr][7] & "| ¦ |  " & $aDataIn[$ptr][8] & "|  " & $pay_amt & "|" & $pay_type & "|  " & $Flag & "| £" & $aDataIn[$ptr][20] & $PrePay)
                Endif

            Next
            ;refresh middle bit
            $Label = GUICtrlSetData($CTRL_Property, $aDataIn[$index][1])
            $Label = GUICtrlSetData($CTRL_Van_Notes, $aDataIn[$index][2])
            $Label = GUICtrlSetData($CTRL_Prev_2_Work, $aDataIn[$index][3])
            $Label = GUICtrlSetData($CTRL_Prev_2_Paid, $aDataIn[$index][4])
            $Label = GUICtrlSetData($CTRL_Prev_1_Work, $aDataIn[$index][5])
            $Label = GUICtrlSetData($CTRL_Prev_1_Paid, $aDataIn[$index][6])
            $Label = GUICtrlSetData($CTRL_Curr_Balance, Number($aDataIn[$index][7]))
            If $aDataIn[$index][15] <> 0 AND $aDataIn[$index][14] <> 1 Then ;cannot split
                $Label = GUICtrlSetState($CTRL_Split_But, $GUI_DISABLE)
            Else
                $Label = GUICtrlSetState($CTRL_Split_But, $GUI_ENABLE)
            Endif

;           $Label = GUICtrlSetData($CTRL_Now_Work, Number($aDataIn[$index][8]))
;           $Label = GUICtrlSetData($CTRL_Now_Paid, Number($aDataIn[$index][9]))
            $Work = $aDataIn[$index][8]
            If $Work = " " Then $Work = ""
            $Paid = $aDataIn[$index][9]
            If $Paid = " " Then $Paid = ""
            $Label = GUICtrlSetData($CTRL_Now_Work, $Work)
            $Label = GUICtrlSetData($CTRL_Now_Paid, $Paid)
            $Label = GUICtrlSetData($CTRL_Work_But, $aDataIn[$index][12])
            $Label = GUICtrlSetData($CTRL_Paid_But, $aDataIn[$index][12])
            If $aDataIn[$index][10] = 1 Then
                $Label = GUICtrlSetState($CTRL_Now_Cash, $GUI_CHECKED)
            Else
                $Label = GUICtrlSetState($CTRL_Now_Cash, $GUI_UNCHECKED)
            Endif

            If $aDataIn[$index][10] = 2 Then
                $Label = GUICtrlSetState($CTRL_Now_Chq, $GUI_CHECKED)
            Else
                $Label = GUICtrlSetState($CTRL_Now_Chq, $GUI_UNCHECKED)
            Endif

            If $aDataIn[$index][10] = 3 Then
                $Label = GUICtrlSetState($CTRL_Now_Split, $GUI_CHECKED)
            Else
                $Label = GUICtrlSetState($CTRL_Now_Split, $GUI_UNCHECKED)
            Endif

            If $aDataIn[$index][11] = 1 Then
                $Label = GUICtrlSetState($CTRL_Attn, $GUI_CHECKED)
            Else
                $Label = GUICtrlSetState($CTRL_Attn, $GUI_UNCHECKED)
            Endif

        $Refresh = 0
        ; set cursor in Work edit field
        $Label = GUICtrlSetState($CTRL_Now_Work, $GUI_FOCUS)
        Endif

        Switch ($key)

 

Link to comment
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
 Share

  • Recently Browsing   0 members

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