Jump to content

HotKeySet("{ENTER}")


hiimjoey11
 Share

Go to solution Solved by Melba23,

Recommended Posts

I want to constantly have a GUI window open, and ONLY capture the "ENTER" key when that GUI window is focused (user is in that window).

For example, I have this GUI set so when i press my Enter key it will refresh all my data.  That works perfectly, except if I have that GUI window open and try and use my enter key anywhere else (browser, notepad, etc) it will still capture it.  

How can I only capture the ENTER button if the GUI is in focus?

I am using this code to capture the enter key!

HotKeySet("{ENTER}", "Enter")

Thanks!

Link to comment
Share on other sites

  • Moderators

hiimjoey11,

Look at GUISetAccelerators in the Help file - it does exactly what you wish. :)

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

hiimjoey11,

Look at GUISetAccelerators in the Help file - it does exactly what you wish. :)

M23

hmm I don't think I am doing this right..

#include <array.au3>
#include <file.au3>
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

$Form1_1 = GUICreate("Form", 240, 118, 192, 124)
$Input1 = GUICtrlCreateInput("", 16, 16, 208, 28,$ES_CENTER)
GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif")
$Button1 = GUICtrlCreateButton("", 16, 48, 208, 25)
GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif")
$Button2 = GUICtrlCreateButton("", 16, 80, 208, 25)
GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif")
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

Dim $EnterArray[1][2] = [["{ENTER}", Enter()]]
GUISetAccelerators($EnterArray)

;HotKeySet("{ENTER}", "Enter")


While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Button1
            $copy = GUICtrlRead($Button1)
            ClipPut($copy)
        Case $Button2
            $copy = GUICtrlRead($Button2)
            ClipPut($copy)
    EndSwitch
WEnd


Func Enter()

    GUICtrlSetData($Button1, $var1)
    GUICtrlSetData($Button2, $var2)

EndFunc   ;==>Enter
Link to comment
Share on other sites

  • Moderators

hiimjoey11,

That code makes no sense. When you press a button you read its text (and there is none to read) to the clipboard - when you want to press ENTER you set the text of the buttons to unknown variables ($var1/2) - and so the buttons still have no text. Overall I am not really surprised you cannot make it work. ;)

As to the GUISetAccelerators section - you need to link the key to a control, not a function - the Help file is quite clear about this. So you will need to add a dummy control to the GUI and then look for it to be fired in the idle loop. But we are getting ahead of ourselves here as until the rest of the script is sorted, it matters little. :D

Please explain what you are trying to do and then we can look into getting the correct code to do it. :)

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

hiimjoey11,

That code makes no sense. When you press a button you read its text (and there is none to read) to the clipboard - when you want to press ENTER you set the text of the buttons to unknown variables ($var1/2) - and so the buttons still have no text. Overall I am not really surprised you cannot make it work. ;)

As to the GUISetAccelerators section - you need to link the key to a control, not a function - the Help file is quite clear about this. So you will need to add a dummy control to the GUI and then look for it to be fired in the idle loop. But we are getting ahead of ourselves here as until the rest of the script is sorted, it matters little. :D

Please explain what you are trying to do and then we can look into getting the correct code to do it. :)

M23

 

I left out the variables because it was information that I didn't want to post to a forum.. For testing purposes, here is working code:

#include <array.au3>
#include <file.au3>
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

$Form1_1 = GUICreate("Form", 240, 118, 192, 124)
$Input1 = GUICtrlCreateInput("", 16, 16, 208, 28,$ES_CENTER)
GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif")
$Button1 = GUICtrlCreateButton("", 16, 48, 208, 25)
GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif")
$Button2 = GUICtrlCreateButton("", 16, 80, 208, 25)
GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif")
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

Dim $EnterArray[1][2] = [["{ENTER}", Enter()]]
GUISetAccelerators($EnterArray)

;HotKeySet("{ENTER}", "Enter")


While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Button1
            $copy = GUICtrlRead($Button1)
            ClipPut($copy)
        Case $Button2
            $copy = GUICtrlRead($Button2)
            ClipPut($copy)
    EndSwitch
WEnd


Func Enter()
    $var1 = "test"
    $var2 = "test2"
    GUICtrlSetData($Button1, $var1)
    GUICtrlSetData($Button2, $var2)

EndFunc   ;==>Enter

Now what I want to do, is type something in the input box, then when I press enter it will GuiCtrlSetData the two buttons.  Then there will be two buttons with information that I can copy once I click on them.  

Now when you say create a dummy control, do you mean create another button on the gui that calls the Enter function or am i misinterpreting this whole thing?

Thanks for the help!

Link to comment
Share on other sites

I tried doing what you said! And it kind of works, but not completely.

#include <array.au3>
#include <file.au3>
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

$Form1_1 = GUICreate("Form", 240, 118, 192, 124)
$Input1 = GUICtrlCreateInput("", 16, 16, 208, 28,$ES_CENTER)
GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif")
$Button1 = GUICtrlCreateButton("", 16, 48, 208, 25)
GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif")
$Button2 = GUICtrlCreateButton("", 16, 80, 208, 25)
GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif")
$Button3 = GUICtrlCreateButton("", 16, 80, 208, 25)
GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif")
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

Dim $EnterArray[1][2] = [["{ENTER}", $Button3]]
GUISetAccelerators($EnterArray)

;HotKeySet("{ENTER}", "Enter")


While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Button1
            $copy = GUICtrlRead($Button1)
            ClipPut($copy)
        Case $Button2
            $copy = GUICtrlRead($Button2)
            ClipPut($copy)
        Case $Button3
            Enter()
    EndSwitch
WEnd


Func Enter()
    $var1 = "test"
    $var2 = "test2"
    GUICtrlSetData($Button1, $var1)
    GUICtrlSetData($Button2, $var2)

EndFunc   ;==>Enter 
Link to comment
Share on other sites

  • Moderators
  • Solution

hiimjoey11,

This works for me - read the comments to see what I meant about needing a dummy control: ;)

#include <GUIConstantsEx.au3>
#include <EditConstants.au3>

$Form1_1 = GUICreate("Form", 240, 118, 192, 124)

$Input1 = GUICtrlCreateInput("", 16, 16, 208, 28, $ES_CENTER)

$Button1 = GUICtrlCreateButton("", 16, 48, 208, 25)
$Button2 = GUICtrlCreateButton("", 16, 80, 208, 25)

; Create a dummy control for the accelerator to action
$cEnter_Dummy = GUICtrlCreateDummy()

GUISetState(@SW_SHOW)

; Link the key to the control
Local $EnterArray[1][2] = [["{ENTER}", $cEnter_Dummy]]
GUISetAccelerators($EnterArray)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Button1
            $copy = GUICtrlRead($Button1)
            ClipPut($copy)
        Case $Button2
            $copy = GUICtrlRead($Button2)
            ClipPut($copy)
        Case $cEnter_Dummy ; Look for the dummy control linked to the accelerator being fired
            Enter()        ; Run the function
    EndSwitch
WEnd

Func Enter()
    $var1 = "test"
    $var2 = "test2"
    GUICtrlSetData($Button1, $var1)
    GUICtrlSetData($Button2, $var2)
EndFunc   ;==>Enter
All clear now? :)

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

hiimjoey11,

This works for me - read the comments to see what I meant about needing a dummy control: ;)

#include <GUIConstantsEx.au3>
#include <EditConstants.au3>

$Form1_1 = GUICreate("Form", 240, 118, 192, 124)

$Input1 = GUICtrlCreateInput("", 16, 16, 208, 28, $ES_CENTER)

$Button1 = GUICtrlCreateButton("", 16, 48, 208, 25)
$Button2 = GUICtrlCreateButton("", 16, 80, 208, 25)

; Create a dummy control for the accelerator to action
$cEnter_Dummy = GUICtrlCreateDummy()

GUISetState(@SW_SHOW)

; Link the key to the control
Local $EnterArray[1][2] = [["{ENTER}", $cEnter_Dummy]]
GUISetAccelerators($EnterArray)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Button1
            $copy = GUICtrlRead($Button1)
            ClipPut($copy)
        Case $Button2
            $copy = GUICtrlRead($Button2)
            ClipPut($copy)
        Case $cEnter_Dummy ; Look for the dummy control linked to the accelerator being fired
            Enter()        ; Run the function
    EndSwitch
WEnd

Func Enter()
    $var1 = "test"
    $var2 = "test2"
    GUICtrlSetData($Button1, $var1)
    GUICtrlSetData($Button2, $var2)
EndFunc   ;==>Enter
All clear now? :)

M23

 

 

WHOOPS! GuiCtrlCreateDummy() is a function lol 

Yes, makes perfect sense! Thanks for introducing me to such a useful feature! It works perfect.

Link to comment
Share on other sites

  • Moderators

hiimjoey11,

Great. :)

Of course you can link the accelerator to an existing control if there is a suitable one - we only needed a dummy here because none of the existing controls fired that particular function. ;)

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