Jump to content

Accelerator Keys


 Share

Recommended Posts

First, I don't have the script written yet AND more importantly I am NOT looking for anyone to do my script.......... 

I am looking for comment back that would tell me if I am correctly understanding something .

So theoretically in the attached piece of code would I be getting the results of

1. Accelerator key would work with List1, List3, List4 and List5.

2. Accelerator key would NOT work with List2

 

I am looking to have Accelerator Key work under conditions involving the List1 - List5 but NOT for conditions with List2.  If this works, it saves me a lot of IF/Then statements and checks.

I am assuming there are people out there with a much, much greater knowledge of Accelerator Keys than mine just reading the help. 

Thanks much

Hobbyist

Global $aAccelKeys[1][2] = [["{ENTER}", $cEnterPressed]]
GUISetAccelerators($aAccelKeys)


While 1
        $iMsg = GUIGetMsg()
         Switch $iMsg

             Case $GUI_EVENT_CLOSE
                 Exit

            Case $list1, $List3, $list4, $list5
                GUISetAccelerators($aAccelKeys)


            Case $List2
        
            GUISetAccelerators(0)
            

endswitch
wend
Link to comment
Share on other sites

Please post a working example of what it is you've tried and isn't working. It's more polite to post something that can be run rather than making someone else come up with all of the missing parts of your post.  Thank you.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

That's not how accelerator keys work. You are only setting the accelerator according to controls clicked. It's not clear what you want to happen when the accelerator is pressed. I normally create a dummy control for something like this, and perhaps I might write something like the following:

Pseudocode

Global $cEnterPressed = GUICtrlCreateDummy()
Global $aAccelKeys[1][2] = [["{ENTER}", $cEnterPressed]]
GUISetAccelerators($aAccelKeys)

While 1
    $iMsg = GUIGetMsg()
    Switch $iMsg

        Case $GUI_EVENT_CLOSE
            Exit

        Case $cEnterPressed, $list1, $List3, $list4, $list5 ; If any of these controls are clicked
            ; Do something

        Case $List2
            ; Do something else

    EndSwitch
WEnd

;

Or maybe you want to run a process on the specified items, in which case you could call a function as shown below.

Case $cEnterPressed
            _MyProcess($list1, $List3, $list4, $list5) ; Process these items
Edited by czardas
Link to comment
Share on other sites

BrewManNH -

Thanks for the response.  As I posted, I have not written it yet or expect anyone to write it.  I am putting thoughts down on paper on best  approach to what I am desiring.  Sorry if you misunderstood what I was asking for. Looking for tips or knowledge on Accelerator Keys -the help file only goes so far.

@

czardas

I have the Dummy key on paper, but forgot to type it in my post -so we are of the same thought. Had it in declarations but not in the logical part. So effecting a particular key function, I understand.

I thought perhaps using the Switch/Case I could turn on/off the Accelerator - for instance, if I understand it right the Switch registers changes by the Case so anytime List1 (for example) changes the Accelerator "key" would be ON but if the change was registered in List2 it would be off.  Could a change in the control, let's say, going from "no show" to "show" (which I am thinking is a change) in effect be registered change recognized by Switch and therefore turn on Accelerator.  I was thinking this could be a short approach to using several IF/Then scenarios (ie design first - code second   :shifty: )

Thanks to all and sorry if there was a misunderstanding as to what I was seeking from the forum.

Hobbyist

Link to comment
Share on other sites

You don't have to apologize: I'm the one who misunderstood what you wanted. I didn't have much time earlier. I just checked the help file and there's nothing wrong with your method in principle, however you say the list changes which is not so clear. For your method to work,  you must actually send a message to one of the the lists: which I assume are controls that you can actually click. Modifying the data by itself will not reset the accelerator keys.

Edited by czardas
Link to comment
Share on other sites

Hobbyist,

The switch statement tests the variable $iMsg against values in the case statements in a timed loop.  So, in a sense, it is monitoring changes to the $iMsg variable ( populated by GuiGetMsg() ).

If $list2 is actioned the accelerator keys are not off, they just do not match that case statement.

I hope that this is clear as it is fundamental to message loop processing.

As to your design, I am not clear on what you want either, however, the following may help.  The code uses a dummy control to determine which control has focus. 

#include <GUIConstantsEx.au3>
#include <array.au3>

local $gui010 = guicreate('')
local $aSize  = wingetclientsize($gui010)
local $aCTL[5]
for $1 = 0 to 4
    $aCTL[$1] = guictrlcreatelist($1+1, 20,$1*50+25,$aSize[0] - 40,20)
next
local $DummyEnter = GUICtrlCreateDummy()
guisetstate()

local $accel[1][2] = [['{ENTER}',$DummyEnter]]
GUISetAccelerators($accel)

local $msg
while 1
    $msg = guigetmsg()
    switch $msg
        case $gui_event_close
            Exit
        case $aCTL[0] to $aCTL[ubound($aCTL)-1]
            ConsoleWrite(guictrlread($msg) & @CRLF)
        case $DummyEnter
            _Enter()
    EndSwitch
WEnd

func _Enter()
    ConsoleWrite(controlgetfocus($gui010) & @CRLF)
endfunc

You might get more specific responses if you shared some of your design details.

Good Luck,

kylomas

Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Link to comment
Share on other sites

@kylomas

Thanks for the reply. No I am not looking for anyone to code FOR me, but rather tap their knowledge before I go off and do something stupid. Clarifying things helps, given the help file is limiting IMO. i don't even have a design since I don't know if what I attempting is possible with Autoit.

Two things I think I  know:

Switch compares a variable to values in a Case statement.

Accelerators changes keys on the key board.

So I was looking at the possibility of having Acclerators keystrokes do something for List2 but function normally for List1.(as an example)

So if I set both List1 and List2 to "disable" & "no show" and then when calling one, changing it to "enable" & "show" I saw that as reading a change in the value. (Only show & use one at a time)

Use Case for each one.

You now say Acclerators are "NOT" off. My question is Why or how is that? Because they were declared?  

The help file says: Passing this function a non-array will unset all accelerators for the given winhandle.

Is this the same or different? What does it mean if it is not what I interpreted. In my mind I am calling that "on" or "off.  Bottom line is, can hitting the same keys on the keyboard be functioning as Accerlerators under one set of conditions and "normal" under different conditions? Does msg evaluate a state of a control as a change in value (back to the swith/case issue)?

Again, I am not looking for others to code for me - I only truly learn by "doing", but admittedly i don't have the vast knowledge so many others have.

Thanks again for your response and note this is just the type of conversation i was needing to learn more of the Autoit stuff.

Hobbyist

Link to comment
Share on other sites

Hobbyist,

Accelerators can be set or unset.  This... 

If $list2 is actioned the accelerator keys are not off, they just do not match that case statement.

  

was a response to this...

 if I understand it right the Switch registers changes by the Case so anytime List1 (for example) changes the Accelerator "key" would be ON but if the change was registered in List2 it would be off.

 

You will need to test this...

 Does msg evaluate a state of a control as a change in value (back to the swith/case issue)?

 

I don't think so but don't know for sure.  Bottom line is you can action a dummy control to handle accelerators wherever you change state.

Admittedly these answers are vague.  They are the best I can do without some design specs.

kylomas

edit:  The code I posted was just an example to show how controls might be manipulated once they are actioned, independent of the message loop.

Edited by kylomas

Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Link to comment
Share on other sites

Does msg evaluate a state of a control as a change in value (back to the swith/case issue)?

 

No - categorically! If this was true, it would lead to all kinds of strange and unpredictable effects. You need to rethink your approach.

Edited by czardas
Link to comment
Share on other sites

I also think knowing if an approach is doable makes more sense than running off coding "in a circle".

 

Most of the time anyway. ;)

Here's one way you could test this. Run the code below. Turn off the accelerator key (ENTER) and see if it comes back on automatically when the button state changes. You will notice that that doesn't work. Notice how confusing it is to work with the GUI. That's the quirky type of behaviour you want to avoid when making design choices.

;

#include <GUIConstantsEx.au3>

Global $hGUI = GUICreate("Test", 200, 100)
Global $hButtonOn = GUICtrlCreateButton("On", 10, 10)
Global $hButtonOff = GUICtrlCreateButton("Off", 50, 10)
Global $hDummmy = GUICtrlCreateDummy()
Global $aAccelKeys[1][2] = [["{ENTER}", $hDummmy]]
GUISetAccelerators($aAccelKeys)

GUISetState(@SW_SHOW)

; Toggle between active and inactive states to test if such a change is registered when calling GUIGetMsg().
AdlibRegister("_ToggleState", 5000) ; Switch the state of $hButtonOn every 5 seconds.

Global $msg

While 1
    $msg = GUIGetMsg()
    Switch $msg
        Case $GUI_EVENT_CLOSE
            ExitLoop

        Case $hDummmy ; The only way to interact with this control is by using the accelerator key.
            _TestAccelerators() ; Test function.

        Case $hButtonOn ; Messages are not automatically registered when the state of the button changes.
            ; The next two lines of code will only run if you click the 'On' button.
            ConsoleWrite("You have just activated accelerators." & @LF)
            GUISetAccelerators($aAccelKeys)

        Case $hButtonOff
            ; Make sure you deactivate the accelerator at some point during testing.
            ; You can reactivate by clicking 'On'.
            GUISetAccelerators(0)
    EndSwitch
WEnd

Func _TestAccelerators() ; Testing accelerator keys.
    MsgBox(0, "", "Accelerators are working!")
EndFunc

Func _ToggleState() ; Turn on and off every 5 seconds.
    If BitAND(GUICtrlGetState($hButtonOn), $GUI_ENABLE) = $GUI_ENABLE Then
        GUICtrlSetState($hButtonOn, $GUI_DISABLE)
    Else
        GUICtrlSetState($hButtonOn, $GUI_ENABLE)
    EndIf
EndFunc
Edited by czardas
Link to comment
Share on other sites

@czardas-

Putting your thoughts together, from the earlier date, I took time to come up with an example involving the Accelerator question.

In this example the Accelerator is needed from processing beyond the controls in the example, thus the Accelrator is "ON".

For the combo box in the script you can make a choice by

1. mouse - drop and click

2. hit a letter key and a word with first letter key appears - then hit enter

3. type any word - hit enter

The issue at hand is the following:

Drop down the combo, use mouse to point to a selection, hit enter key produces

1. required movement to the next input (ie Amount)

2. but the combo box is blank.

Note though the message box (used just for this testing) DOES have the value from the combo box.

After your comments and example i thought the design might be to use the Combo drop down (true or false) to set or unset the Accelerator. But I did not get the result I was looking for which is to maintain 1 - 3 above PLUS resolve the issue of blank combo box.

Any thoughts on direction would be appreciated. You have been a big help or I wouldn't be this far.

Hobbyist

(ps - I just dump a lot of "includes" at the beginning because I'm never sure what I will be adding - I clean it up later)

#include <Array.au3>
#include <ButtonConstants.au3>
#include <ColorConstants.au3>
#include <ComboConstants.au3>
#include <Date.au3>
#include <EditConstants.au3>
#include <File.au3>
#include <GUIComboBox.au3>
#include <GUIConstantsEx.au3>
#include <GUIListBox.au3>
#include <GuiListView.au3>
#include <ListViewConstants.au3>
#include <Misc.au3>
#include <MsgBoxConstants.au3>
#include <StaticConstants.au3>
#include <String.au3>
#include <WindowsConstants.au3>
#include <StringConstants.au3>
#include <FileConstants.au3>
#include <GuiTab.au3>
 #include <GuiButton.au3>
 #include <GuiMenu.au3>
 #include <WinAPI.au3>
 #include <Constants.au3>



#Region ### START Koda GUI section ### Form=C:\Users\Steven\Autoit Trys\Vendors Trials\My combo Form Test.kxf
$main = GUICreate("Test Screen", 680, 515, 150, 100)

$combo_test = GUICtrlCreateCombo("", 10, 26, 70, 25)
GUICtrlSetData(-1, "a")
GUICtrlSetState($combo_test,$GUI_show)
$Button12 = GUICtrlCreateButton("Clear", 10, 60, 158, 33)
GUICtrlSetState($Button12,$GUI_enable)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
$AEamounts = GUICtrlCreateInput("xxx", 96, 26, 70, 21);
GUICtrlSetState($AEamounts,$GUI_show)

GUISetState(@SW_SHOW)

$cEnterPressed = GUICtrlCreateDummy()
global $MMM, $NNN
Global $tInfo, $fCombo2 = False
Global $AEmoney
Global $fCombo2 = False
Global $aAccelKeys[1][2] = [["{ENTER}", $cEnterPressed]];x <<<<<<<<<<<<<<<<<<<<<<<<< accelerator  ON
GUISetAccelerators($aAccelKeys);x
;GUISetAccelerators(0)



Dim $array_2[10] = ["","Nails", "Gas","Wood", "Misc", "Wire", "Vents","Cement","R-Bar","Tape"]
$a = ""
For $i = 0 To UBound($array_2) - 1
    $a &= $array_2[$i] & "|"
Next

GUICtrlSetData($combo_test, $a)
GUIRegisterMsg($WM_COMMAND, "WM_COMMAND")

$listswitch = 1 ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<  refers to a listview and its show or no show


_GUICtrlComboBox_GetComboBoxInfo($combo_test, $tInfo)
$hEdit2 = DllStructGetData($tInfo, "hEdit")

GUISetState()


While 1


        $iMsg = GUIGetMsg()
         Switch $iMsg
             Case $GUI_EVENT_CLOSE
                 Exit


        Case $GUI_EVENT_PRIMARYUP

            If $fCombo2   Then
                   GUICtrlSetState ($AEamounts, $GUI_FOCUS)
                EndIf

        Case  $cEnterPressed  ; Dummy

                If _WinAPI_GetFocus() = $hEdit2 And GUICtrlRead($combo_test)<> "" Then
                    GUICtrlRead($combo_test)
                    GUICtrlSetState ($AEamounts, $GUI_FOCUS)


                EndIf

        case $Button12  ;clear if needed

                GUICtrlSetState($combo_test,$GUI_FOCUS)
                _GUICtrlComboBox_SetCurSel ( $combo_test ,  -1 )
                GUICtrlSetData($AEamounts,"")

        Case $AEamounts

            $AEmoney = GUICtrlRead ( $AEamounts )

            Switch  $listswitch  ;for listview status show or no show

                    Case 1


                $AEmoney = GUICtrlRead ( $AEamounts )

                if ($AEmoney/$AEmoney) = 1 And _IsPressed("0D") Then ; checking for number entry
                        MsgBox($MB_SYSTEMMODAL, "Information", "verify " &$AEmoney &"' " &GUICtrlRead($combo_test) )    ;just see data for now
                        GUICtrlSetState($combo_test,$GUI_FOCUS)
                        _GUICtrlComboBox_SetCurSel ( $combo_test ,  -1 )
                        GUICtrlSetData($AEamounts,"")
                           EndIf
                    EndSwitch
        EndSwitch



    If _GUICtrlComboBox_GetDroppedState($combo_test) = True Then
        $fCombo2 = True

    EndIf



WEnd

Func _Edit_Changed($combo_test)
     _GUICtrlComboBox_AutoComplete($combo_test)
EndFunc   ;==>_Edit_Changed

Func WM_COMMAND($hWnd, $iMsg, $iwParam, $ilParam)
    #forceref $hWnd, $iMsg
    $iIDFrom = BitAND($iwParam, 0xFFFF) ; Low Word
    $iCode = BitShift($iwParam, 16) ; Hi Word
    Switch $iCode
          Case $CBN_EDITCHANGE
            Switch $iIDFrom
                    Case $combo_test
                     _Edit_Changed($combo_test)
            EndSwitch
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_COMMAND
Edited by Hobbyist
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...