Jump to content

If GUISetAccelerators() for a GUI then, what is for a specific control ?


kcvinu
 Share

Recommended Posts

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.

Spoiler

My Contributions

Glance GUI Library - A gui library based on Windows api functions. Written in Nim programming language.

UDF Link Viewer   --- A tool to visit the links of some most important UDFs 

 Includer_2  ----- A tool to type the #include statement automatically 

 Digits To Date  ----- date from 3 integer values

PrintList ----- prints arrays into console for testing.

 Alert  ------ An alternative for MsgBox 

 MousePosition ------- A simple tooltip display of mouse position

GRM Helper -------- A littile tool to help writing code with GUIRegisterMsg function

Access_UDF  -------- An UDF for working with access database files. (.*accdb only)

 

Link to comment
Share on other sites

  • Moderators

kcvinu,

Just check which control has focus when the Accelerator key is actioned and only proceed if the correct one is focused.

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 I have tried, but not succeeded. What is worng with this code ?

#include <WindowsConstants.au3>
#include <GUIConstantsEx.au3>
#include <GuiButton.au3>

Local $hGUI = GUICreate("Window", 381, 237, -1, -1)
Local $hButton = GUICtrlCreateButton("Button", 97, 145, 192, 77)
Local $hInput = GUICtrlCreateInput("", 60, 37, 267, 35)
Local $hInput2 = GUICtrlCreateInput("", 60, 97, 267, 35)
Local $Accle = [["{ENTER}",$hButton]]
GUISetAccelerators($Accle)

GUISetState()

While 1
    $hMsg = GUIGetMsg()
    Switch $hMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $hInput

        Case $hButton
            If GUICtrlGetState($hInput) = $GUI_FOCUS Then
                BClick()
            EndIf
    EndSwitch
WEnd


Func BClick()
    MsgBox(0,"","Button is Clicked")
EndFunc

 

Edited by kcvinu
Spoiler

My Contributions

Glance GUI Library - A gui library based on Windows api functions. Written in Nim programming language.

UDF Link Viewer   --- A tool to visit the links of some most important UDFs 

 Includer_2  ----- A tool to type the #include statement automatically 

 Digits To Date  ----- date from 3 integer values

PrintList ----- prints arrays into console for testing.

 Alert  ------ An alternative for MsgBox 

 MousePosition ------- A simple tooltip display of mouse position

GRM Helper -------- A littile tool to help writing code with GUIRegisterMsg function

Access_UDF  -------- An UDF for working with access database files. (.*accdb only)

 

Link to comment
Share on other sites

@TheDcoder , I am learing about dummy controls. 

Spoiler

My Contributions

Glance GUI Library - A gui library based on Windows api functions. Written in Nim programming language.

UDF Link Viewer   --- A tool to visit the links of some most important UDFs 

 Includer_2  ----- A tool to type the #include statement automatically 

 Digits To Date  ----- date from 3 integer values

PrintList ----- prints arrays into console for testing.

 Alert  ------ An alternative for MsgBox 

 MousePosition ------- A simple tooltip display of mouse position

GRM Helper -------- A littile tool to help writing code with GUIRegisterMsg function

Access_UDF  -------- An UDF for working with access database files. (.*accdb only)

 

Link to comment
Share on other sites

  • Moderators

kcvinu,

I always use _WinAPI_GetFocus to test which control has it:

Case $hButton

            If _WinAPI_GetFocus() = GUICtrlGetHandle($hInput) Then
                BClick()
            EndIf

and that works for me.

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

Here is a live example which I use in my program:

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

Global $g_hMainGUI = GUICreate("Test")

Global $g_idMainGUI_YesDummy = GUICtrlCreateDummy()
Global $g_idMainGUI_NoDummy = GUICtrlCreateDummy()
Global $g_idMainGUI_TryAgainDummy = GUICtrlCreateDummy()
Global $g_idMainGUI_AbortDummy = GUICtrlCreateDummy()

Local $aAccelKeys[4][2] = [["y", $g_idMainGUI_YesDummy], ["n", $g_idMainGUI_NoDummy], ["t", $g_idMainGUI_TryAgainDummy], ["a", $g_idMainGUI_AbortDummy]]
GUISetAccelerators($aAccelKeys, $g_hMainGUI)

GUISetState()

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit

        Case $g_idMainGUI_YesDummy
            MsgBox($MB_OK, "Test", "You pressed 'y' which means Yes!")

        Case $g_idMainGUI_NoDummy
            MsgBox($MB_OK, "Test", "You pressed 'n' which means No!")

        Case $g_idMainGUI_TryAgainDummy
            MsgBox($MB_OK, "Test", "You pressed 't' which means Try Again!")

        Case $g_idMainGUI_AbortDummy
            MsgBox($MB_OK, "Test", "You pressed 'a' which means Abort!")
    EndSwitch
WEnd

TD :D

Edited by TheDcoder

EasyCodeIt - A cross-platform AutoIt implementation - Fund the development! (GitHub will double your donations for a limited time)

DcodingTheWeb Forum - Follow for updates and Join for discussion

Link to comment
Share on other sites

@TheDcoder , Thanks for the example. 

@Melba23 , What i was planned is to display the MsgBox in 2 conditions.

1. when user presses enter after typing in text box

2. when user clicks the button with mouse. 

So this is the way i solved this problem. Please look this and tell me if there is any better way.

Case $hButton
        If _WinAPI_GetFocus() = GUICtrlGetHandle($hInput) Or _WinAPI_GetFocus() = GUICtrlGetHandle($hButton) Then
            BClick()
        EndIf

 

Spoiler

My Contributions

Glance GUI Library - A gui library based on Windows api functions. Written in Nim programming language.

UDF Link Viewer   --- A tool to visit the links of some most important UDFs 

 Includer_2  ----- A tool to type the #include statement automatically 

 Digits To Date  ----- date from 3 integer values

PrintList ----- prints arrays into console for testing.

 Alert  ------ An alternative for MsgBox 

 MousePosition ------- A simple tooltip display of mouse position

GRM Helper -------- A littile tool to help writing code with GUIRegisterMsg function

Access_UDF  -------- An UDF for working with access database files. (.*accdb only)

 

Link to comment
Share on other sites

  • Moderators

kcvinu,

I would use a dummy control like this:

#include <GUIConstantsEx.au3>
#include <WinAPI.au3>

Local $hGUI = GUICreate("Window", 381, 237, -1, -1)
Local $hButton = GUICtrlCreateButton("Button", 97, 145, 192, 77)
Local $hInput = GUICtrlCreateInput("", 60, 37, 267, 35)
Local $hInput2 = GUICtrlCreateInput("", 60, 97, 267, 35)
Local $cInputDummy = GUICtrlCreateDummy()

GUISetState()

Local $Accle = [["{ENTER}",$cInputDummy]]
GUISetAccelerators($Accle)

While 1
    $hMsg = GUIGetMsg()
    Switch $hMsg

        Case $GUI_EVENT_CLOSE
            Exit
        Case $cInputDummy

            If _WinAPI_GetFocus() = GUICtrlGetHandle($hInput) Then
                BClick()
            EndIf

        Case $hButton

            BClick()
    EndSwitch

WEnd



Func BClick()
    MsgBox(0,"","Button is Clicked")
EndFunc

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 a lot.  :)

Spoiler

My Contributions

Glance GUI Library - A gui library based on Windows api functions. Written in Nim programming language.

UDF Link Viewer   --- A tool to visit the links of some most important UDFs 

 Includer_2  ----- A tool to type the #include statement automatically 

 Digits To Date  ----- date from 3 integer values

PrintList ----- prints arrays into console for testing.

 Alert  ------ An alternative for MsgBox 

 MousePosition ------- A simple tooltip display of mouse position

GRM Helper -------- A littile tool to help writing code with GUIRegisterMsg function

Access_UDF  -------- An UDF for working with access database files. (.*accdb only)

 

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

×
×
  • Create New...