Jump to content

GUISetAccelerators stopped working


unity06
 Share

Recommended Posts

Hi Forum,

I am literally pulling my hair out at the moment.

I wrote a relatively simple script which comprises of a GUI interface with a few buttons and an embedded Internet Expolorer window in it which lets me browse HTML files and enter some data.

I have recently reinstalled windows and my program still works, but the hotkeys have stopped working so I have to manually click on buttons now.

I cannot understand why but the code below does nothing now.... where on the previous windows installation it worked fine.

global $AccelKeys[3][3] = [["{left}", $GUI_Button_Back],["{right}", $GUI_Button_Forward],["{enter}", $GUI_Button_Buy]]
    GUISetAccelerators($AccelKeys)

 

The full code is shown below if it will help it is basically an adaptation to the HelpFile script about GuiSet Accelerators.

I would really appreciate some help,. Been at it for nearly 2 hours and still cannot understand what the problem is. I am not an advanced user but I have always got through problems before on my own most of the time.

Func Page_GUI()
    global $price_check = 0
    global $pp = 1
    global $item_id
    global $item_id2
    global $memory_price
    global $memory_price_pos
    global $GUI
    _FileReadToArray("C:\gixen.txt",$item_id)
    _FileReadToArray("C:\gixen2.txt",$item_id2)
    $direct = inputbox("What is the directory?","Input the directory","C:\1CRAWLER\")

    GUICreate("GUI",@desktopwidth,@desktopheight)
        $oIE = ObjCreate("Shell.Explorer.2")



    global $page = 1
    global $pricetag

    global $dirsize = DirGetSize($direct,1)

    $GUI = GUICreate("Embedded Web control Test", @DesktopWidth-100, @DesktopHeight-100, (@DesktopWidth - 640) / 2, (@DesktopHeight - 580) / 2, BitOR($WS_OVERLAPPEDWINDOW, $WS_CLIPSIBLINGS, $WS_CLIPCHILDREN))
    GUICtrlCreateObj($oIE, 10, 40, @DesktopWidth-200, @DesktopHeight-250)
    $GUI_Button_Back = GUICtrlCreateButton("Back",100,@DesktopHeight-200, 100, 30)
    $GUI_Button_Forward = GUICtrlCreateButton("Forward", 200, @DesktopHeight-200, 100, 30)
    $GUI_Button_Buy = GUICtrlCreateButton("Buy", 300, @DesktopHeight-200, 100, 30)
    $GUI_Button_Stop = GUICtrlCreateButton("Write Excel", 400, @DesktopHeight-200, 100, 30)
    $GUI_Page_Label = GUICTRLCreateLabel($page & " of " & $dirsize[2],25,25,250,50)
    $GUI_Price_Box = GUICtrlCreateInput("",500,@DesktopHeight-200,300,80)
    $GUI_iNum_Label = GUICtrlCreateLabel("",900,@DesktopHeight-200,400,50)
    GUICtrlSetFont($GUI_Price_Box,40)
    GUICtrlSetFont($GUI_iNum_Label,40)
    GUICtrlSetColor($GUI_iNum_Label,0xBDBDBD)

    $inumber = fileread($direct & $page & "\log.html",12)
    GUICtrlSetData($GUI_iNum_Label,$inumber)

    GUISetState() ;Show GUI
    WinSetState($GUI, "", @SW_MAXIMIZE)
    GUICtrlSetState($GUI, $GUI_FOCUS)
    ;msgbox(1,"test",$direct & $page & "\log.html")
    $oIE.navigate($direct & $page & "\log.html")


    ;================check if already bid price exists==================
    If FileExists("C:\gixen.txt") Then
    $price_check = 0
    $pp = 1

        $price_check = _ArraySearch($item_id2,$inumber)

        if $price_check > 0 then
            $memory_price_pos = StringInStr($item_id[$price_check],',')
            $memory_price = StringMid($item_id[$price_check],1,$memory_price_pos-1)

            GUICtrlSetData($GUI_Price_Box,$memory_price)
        Else
        ;donothing
        Endif
    Endif


    ;====================================================================

    global $AccelKeys[3][3] = [["{left}", $GUI_Button_Back],["{right}", $GUI_Button_Forward],["{enter}", $GUI_Button_Buy]]
    GUISetAccelerators($AccelKeys)

    While 1
        $msg = GUIGetMsg()

        Select
            Case $msg = $GUI_EVENT_CLOSE
                ExitLoop


            Case $msg = $GUI_Button_Buy

                If FileExists("C:\gixen.txt") Then
                $price_check = 0
                $price_check = _ArraySearch($item_id2,$inumber)

                    if $price_check > 0 then
                        $pricetag = GUIctrlread($GUI_Price_Box)
                        _FileWriteToLine("C:\gixen.txt",$price_check,$pricetag & "," & $inumber,1)
                        $page = $page + 1
                        GUICtrlSetData($GUI_Page_Label,$page & " of " & $dirsize[2])
                        $oIE.navigate($direct & $page & "\log.html")
                        $inumber = fileread($direct & $page & "\log.html",12)
                        GUICtrlSetData($GUI_iNum_Label,$inumber)
                        GUICtrlSetData($GUI_Price_Box,"")

                    Else
                        $pricetag = GUIctrlread($GUI_Price_Box)
                        FileWriteLine("C:\gixen.txt",$pricetag & "," & $inumber)
                        FileWriteLine("C:\gixen2.txt",$inumber)
                        $page = $page + 1
                        GUICtrlSetData($GUI_Page_Label,$page & " of " & $dirsize[2])
                        $oIE.navigate($direct & $page & "\log.html")
                        $inumber = fileread($direct & $page & "\log.html",12)
                        GUICtrlSetData($GUI_iNum_Label,$inumber)
                        GUICtrlSetData($GUI_Price_Box,"")

                    Endif

                    Else
                        $pricetag = GUIctrlread($GUI_Price_Box)
                        FileWriteLine("C:\gixen.txt",$pricetag & "," & $inumber)
                        FileWriteLine("C:\gixen2.txt",$inumber)
                        $page = $page + 1
                        GUICtrlSetData($GUI_Page_Label,$page & " of " & $dirsize[2])
                        $oIE.navigate($direct & $page & "\log.html")
                        $inumber = fileread($direct & $page & "\log.html",12)
                        GUICtrlSetData($GUI_iNum_Label,$inumber)
                        GUICtrlSetData($GUI_Price_Box,"")


                Endif

                ;================================

                If FileExists("C:\gixen.txt") Then
    $price_check = 0
    $pp = 1

        $price_check = _ArraySearch($item_id2,$inumber)

        if $price_check > 0 then
            $memory_price_pos = StringInStr($item_id[$price_check],',')
            $memory_price = StringMid($item_id[$price_check],1,$memory_price_pos-1)

            GUICtrlSetData($GUI_Price_Box,$memory_price)
        Else
        ;donothing
        Endif
    Endif


            Case $msg = $GUI_Button_Back
                _FileReadToArray("C:\gixen.txt",$item_id)
                _FileReadToArray("C:\gixen2.txt",$item_id2)
                If $page > 1 Then
                $page = $page - 1
                GUICtrlSetData($GUI_Page_Label,$page & " of " & $dirsize[2])
                $inumber = fileread($direct & $page & "\log.html",12)
                GUICtrlSetData($GUI_iNum_Label,$inumber)
                Endif
                $oIE.navigate($direct & $page & "\log.html")

                If FileExists("C:\gixen.txt") Then
    $price_check = 0
    $pp = 1

        $price_check = _ArraySearch($item_id2,$inumber)

        if $price_check > 0 then
            $memory_price_pos = StringInStr($item_id[$price_check],',')
            $memory_price = StringMid($item_id[$price_check],1,$memory_price_pos-1)

            GUICtrlSetData($GUI_Price_Box,$memory_price)
        Else
        GUICtrlSetData($GUI_Price_Box,"")
        Endif
    Endif


            Case $msg = $GUI_Button_Forward
                _FileReadToArray("C:\gixen.txt",$item_id)
                _FileReadToArray("C:\gixen2.txt",$item_id2)
                $page = $page + 1
                GUICtrlSetData($GUI_Page_Label,$page & " of " & $dirsize[2])
                $oIE.navigate($direct & $page & "\log.html")
                $inumber = fileread($direct & $page & "\log.html",12)
                GUICtrlSetData($GUI_iNum_Label,$inumber)

                If FileExists("C:\gixen.txt") Then
    $price_check = 0
    $pp = 1

        $price_check = _ArraySearch($item_id2,$inumber)

        if $price_check > 0 then
            $memory_price_pos = StringInStr($item_id[$price_check],',')
            $memory_price = StringMid($item_id[$price_check],1,$memory_price_pos-1)

            GUICtrlSetData($GUI_Price_Box,$memory_price)
        Else
        GUICtrlSetData($GUI_Price_Box,"")
        Endif
    Endif

            Case $msg = $GUI_Button_Stop
                ;WRITE EXCEL
        EndSelect

    WEnd



    GUIDelete()

Endfunc

 

Link to comment
Share on other sites

  • Moderators

unity06,

It seems that you cannot use those particular keys as Accelerators in this case. They are acted upon by Windows before they get intercepted by AutoIt - the arrow keys to move focus between button and the ENTER key to action the button with focus. If you add a modifier (I used CTRL):

Local $AccelKeys[3][2] = [["^{LEFT}", $GUI_Button_Back], ["^{RIGHT}", $GUI_Button_Forward], ["^{ENTER}", $GUI_Button_Buy]]

then the Accelerator keys work as expected.

I have no idea why they worked before - did you upgrade your Windows when you reinstalled?

M23

Edit: See below for the real answer!

Edited by Melba23

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

Hi Melba23,

I have bought a new hard drive and installed a fresh copy of Windows 7 Ultimate 64bit on it. Exactly the same OS I had before.

I have tried your suggestion, but it still does not work.

But if I modify the example script which teaches about GUIAccelerators in help file, it does work!

Struggling to think what might be different. Maybe the version of AutoIT ?.... Thats my next step I think.

UPDATE: Checked the Autoit a. Versions are the same. Running v3.3.12.0 on both installations. This is getting very confusing.

#include <GUIConstantsEx.au3>
#include <MsgBoxConstants.au3>

Example()

Func Example()
    GUICreate("Custom MsgBox", 225, 80)

    GUICtrlCreateLabel("Please select a button.", 10, 10)
    Local $idYes = GUICtrlCreateButton("Yes", 10, 50, 65, 25)
    Local $idNo = GUICtrlCreateButton("No", 80, 50, 65, 25)
    Local $idExit = GUICtrlCreateButton("Exit", 150, 50, 65, 25)

    ; Set GUIAccelerators for the button controlIDs, these being Ctrl + y and Ctrl + n
    Local $aAccelKeys[2][2] = [["{left}", $idYes], ["{right}", $idNo]]
    GUISetAccelerators($aAccelKeys)

    GUISetState(@SW_SHOW) ; Display the GUI.

    While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE
                MsgBox($MB_SYSTEMMODAL, "You selected", "Close")
                ExitLoop

            Case $idYes
                MsgBox($MB_SYSTEMMODAL, "You selected", "Yes") ; Displays if the button was selected or the hotkey combination Ctrl + y was pressed.

            Case $idNo
                MsgBox($MB_SYSTEMMODAL, "You selected", "No") ; Displays if the button was selected or the hotkey combination Ctrl + n was pressed.

            Case $idExit
                MsgBox($MB_SYSTEMMODAL, "You selected", "Exit")
                ExitLoop

        EndSwitch
    WEnd
    GUIDelete() ; Delete the GUI.
EndFunc   ;==>Example

 

Edited by unity06
Link to comment
Share on other sites

  • Moderators

unity06,

It works for me too - so why does it not in your script? I like puzzles.....

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

  • Moderators

unity06,

Got it! You are declaring the array as [3][3] - GUISetAccelerators expects an array with only 2 columns and so fails. Declare the array properly and it works:

global $AccelKeys[3][2] = [["{left}", $GUI_Button_Back],["{right}", $GUI_Button_Forward],["{enter}", $GUI_Button_Buy]]

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

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...