Jump to content

Hotkeyset


Go to solution Solved by JLogan3o13,

Recommended Posts

How do i set a hotkey to a button i made in the Graphical user interface in koda? Well, yet again, i'm a newbie to this. Your help will be appreciated.

Any code or something to help explain a bit more of what you need? :)

Link to comment
Share on other sites

  • Moderators

As olo pointed out, how about posting the code for the GUI you created? Help us help you :)

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
Share on other sites

As i said, "I'm new your help would be greatly appreciated :)
Well, This is a program i am making for paint. I want it to click around 7 times whenever i press a special key. Plus, I want a hotkey set to $Button1. So that i don't have to press start everytime.
Well, here is the code : 

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 251, 245, 927, 209)
$Button1 = GUICtrlCreateButton("Start", 24, 16, 75, 25)
$Button2 = GUICtrlCreateButton("Instructions", 24, 64, 75, 25)
$Button3 = GUICtrlCreateButton("Quit", 24, 104, 75, 25)
$Label1 = GUICtrlCreateLabel("Made by GeekyBunny", 128, 96, 84, 81)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Button1
            If  $Button1 <> 0 then
                MouseClick("Left")
                MouseWheel("Down")
                MouseClick("Left")
                MouseWheel("Down")
                MouseClick("Left")
                MouseWheel("Down")
                EndIf
        Case $Button2
            MsgBox(0,"Instructions","Try")
        Case $Button3
            Exit
    EndSwitch
WEnd
Edited by GeekyBunny
Link to comment
Share on other sites

  • Moderators

I guess I am confused. You say you want to take some action on $Button1, but you don't want to click it all the time. How is your program to know you want to take said action if you don't click the button? And if you set a hotkey to perform the same steps as clicking the button, aren't you doubling your effort for the same number of clicks/button presses?

 

Edit: To answer your question, despite the confusion your approach brings me - you would look at HotKeySet in the help file sd mrflibblehat suggested.

Edited by JLogan3o13

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
Share on other sites

I guess I am confused. You say you want to take some action on $Button1, but you don't want to click it all the time. How is your program to know you want to take said action if you don't click the button? And if you set a hotkey to perform the same steps as clicking the button, aren't you doubling your effort for the same number of clicks/button presses?

 

Edit: To answer your question, despite the confusion your approach brings me - you would look at HotKeySet in the help file sd mrflibblehat suggested.

(I can make only 4 more posts)

Erm, sorry for troubling you what i meant to say is that the i want a hotkeyset as an alternative for the button i press so that i keep hitting the hotkey instead of going back to the form1 and click the button. Like isn't there a way to give the button a hotkey so that whenever i press a certain key, say, "F5", it completes a certain function which i had written in the button.

Link to comment
Share on other sites

  • Moderators
  • Solution

Sure you can. Something like this:

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
HotKeySet("{F5}", "_myFunc")

Local $msg

GUICreate("Test", 300, 300)
$Button1 = GUICtrlCreateButton("Button 1", 10, 10, 100,30)

GUISetState(@SW_SHOW)

    While 1
        $msg = GUIGetMsg()
            Select
                Case $msg = $GUI_EVENT_CLOSE
                    ExitLoop
                Case $msg = $Button1
                    _myFunc()
            EndSelect
    WEnd

GUIDelete()

Func _myFunc()
    If $msg = $Button1 Then
        MsgBox(0, "", "I got here from the button")
    Else
        MsgBox(0, "", "I got here from a hotkey")
    EndIf
EndFunc

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
Share on other sites

  • Moderators

Correct. Typically they are put at the end, after the "Main" portion of the script, but they can go anywhere.

 

Edit: Fixed horrible spelling.

Edited by JLogan3o13

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
Share on other sites

  • Moderators

GeekyBunny,

I have lifted the "New Members" post restriction for you. :)

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

GeekyBunny,

I have lifted the "New Members" post restriction for you. :)

M23

Thank you very much! :D 

You guys are the best! :3

Now, i can post when i want without waiting till the morning but for now, All my problems are solved due to JLogan3o13's answer! :) 

But still thank you very much :)

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