Jump to content

Adding Functions/hotkeys?


Recommended Posts

ok so i have a working script with a GUI and i was wondering if there was a way to add hotkeys for each button select. if it is possible (which i know it is i just have never actually used hotkeys in a script before)then is it possible to use the number pad numbers? i just want $Button1 to get selected when i press "1" on the number pad. and can this be done without the GUI as the focus window?? here's the script:

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
$Form1 = GUICreate("GUI", 401, 201, 723, 228)
GUISetBkColor(0x0000FF)
$Button1 = GUICtrlCreateButton("1 Items", 40, 32, 83, 41, $WS_GROUP)
GUICtrlSetBkColor(-1, 0x00FF00)
$Button2 = GUICtrlCreateButton("2 Items", 152, 32, 83, 41, $WS_GROUP)
GUICtrlSetBkColor(-1, 0x00FF00)
$Button3 = GUICtrlCreateButton("3 Items", 264, 32, 83, 41, $WS_GROUP)
GUICtrlSetBkColor(-1, 0x00FF00)
GUISetState(@SW_SHOW)
Global $PixelCheck1, $PixelCheck2, $PixelCheck3, $NewCheck

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $Button1
            MouseClick( "left", 977, 855, 3) ; Select Item
            Sleep(250)
            MouseClick( "right", 977, 855) ;right click
            SLeep(250)
            Send("c") ;copy
            $PixelCheck2 = PixelCheckSum(40, 950, 100, 960)
            MouseClick( "left", 1815, 300)
            Sleep(1000)
            While $PixelCheck2 <> $NewCheck
                $NewCheck = PixelCheckSum(40, 950, 100, 960)
                Sleep(500)
            WEnd
            MouseClick( "right", 842, 256) ; right click search box
            Sleep(250)
            Send("p") ;
            Sleep(250)
            Send("{ENTER}")

        Case $Button2
            $PixelCheck1 = PixelCheckSum(40, 950, 100, 960)
            MouseClick( "left", 1076, 854, 3)
            Sleep(250)
            MouseClick( "right", 1076, 854)
            Sleep(250)
            Send("c")
            Sleep(250)
            MouseClick( "left", 1815, 300)
            Sleep(1000)
            While $PixelCheck1 <> $NewCheck
                $NewCheck = PixelCheckSum(40, 950, 100, 960)
                Sleep(500)
            WEnd
            MouseClick( "right", 842, 256) ; right click in search box
            Sleep(250)
            Send("p") ; paste
            Sleep(250)
            Send("{ENTER}") ; press search
            Sleep(250)
            MouseClick( "left", 230, 16) ;~ Home Tab
            Sleep(250)
            MouseClick( "left", 876, 853, 3)
            Sleep(250)
            MouseClick( "right", 876, 853)
            Sleep(250)
            Send("c")
            Sleep(250)
            $PixelCheck2 = PixelCheckSum(40, 950, 100, 960)
            Sleep(250)
            MouseClick( "left", 1815, 300)
            Sleep(1000)
            While $PixelCheck2 <> $NewCheck
                $NewCheck = PixelCheckSum(40, 950, 100, 960)
                Sleep(500)

            WEnd
            MouseClick( "right", 842, 256)
            Sleep(250)
            Send("p")
            Sleep(250)
            Send("{ENTER}")

        Case $Button3

            $PixelCheck1 = PixelCheckSum(40, 950, 100, 960)
            MouseClick( "left", 1113, 855, 3)
            Sleep(250)
            MouseClick( "right", 1113, 855)
            Sleep(250)
            Send("c")
            MouseClick( "left", 1815, 300)
            Sleep(1000)
            While $PixelCheck1 <> $NewCheck
                $NewCheck = PixelCheckSum(40, 950, 100, 960)
                Sleep(500)
            WEnd
            MouseClick( "right", 842, 256)
            Sleep(250)
            Send("p")
            Sleep(250)
            Send("{ENTER}")
            Sleep(250)
            MouseClick( "left", 230, 16) ;~ Home Tab
            Sleep(250)
            MouseClick( "left", 977, 855, 3)
            Sleep(250)
            MouseClick( "right", 977, 855)
            SLeep(250)
            Send("c")
            $PixelCheck2 = PixelCheckSum(40, 950, 100, 960)
            MouseClick( "left", 1815, 300)
            Sleep(1000)
            While $PixelCheck2 <> $NewCheck
                $NewCheck = PixelCheckSum(40, 950, 100, 960)
                Sleep(500)
            WEnd
            MouseClick( "right", 842, 256)
            Sleep(250)
            Send("p")
            Sleep(250)
            Send("{ENTER}")
            Sleep(250)
            MouseClick( "left", 230, 16) ;~ Home Tab
            Sleep(500)
            MouseClick( "left", 847, 855, 3)
            Sleep(500)
            MouseClick( "right", 847, 855)
            SLeep(500)
            Send("c")
            $PixelCheck3 = PixelCheckSum(40, 950, 100, 960)
            MouseClick( "left", 1815, 300)
            Sleep(1000)
            While $PixelCheck3 <> $NewCheck
                $NewCheck = PixelCheckSum(40, 950, 100, 960)
                Sleep(500)
            WEnd
            MouseClick( "right", 842, 256)
            Sleep(250)
            Send("p")
            Sleep(250)
            Send("{ENTER}")

        Case $GUI_EVENT_CLOSE
            Exit

    EndSwitch
WEnd
Link to comment
Share on other sites

Look at HotKeySet() in the helpfile :)

ok well i looked and i got this far:

HotKeySet("{NUMPAD1}", "Button1")
HotKeySet("{NUMPAD2}", "Button2")
HotKeySet("{NUMPAD3}", "Button3")

Func Button1()
    MsgBox(4096,"","This is a message 1.")
EndFunc

Func Button2()
    MsgBox(4096,"","This is a message 2.")
EndFunc

Func Button3()
    MsgBox(4096,"","This is a message 3.")
EndFunc

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

    EndSwitch
WEnd

i collapsed the cases to save space. how do i get it to "send" a button click and run through the case i set it to??

Link to comment
Share on other sites

hello kidney,

Search for GUISetAccelerators() in the help-file, here's a quick demo, :)

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Demo1", 200, 45)
$Button1 = GUICtrlCreateButton("Click me or press ENTER", 25, 10, 150, 25)
GUISetState(@SW_SHOW)
Dim $Form1_AccelTable[1][2] = [["{ENTER}", $Button1]]
GUISetAccelerators($Form1_AccelTable)
#endregion ### END Koda GUI section ###

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Button1
            MsgBox(64, @ScriptName, "Hello from Button1")
    EndSwitch
WEnd

Hope this helps,

-smartee

Edit:spacing

Edited by smartee
Link to comment
Share on other sites

i collapsed the cases to save space. how do i get it to "send" a button click and run through the case i set it to??

Button click what? Use the function in both the control response and the hotkey.

hello kidney,

Search for GUISetAccelerators() in the help-file, here's a quick demo, :)

That only works when the GUI is focused, that's not how I read the OP. Edited by AdmiralManHairAlkex
Link to comment
Share on other sites

That only works when the GUI is focused, that's not how I read the OP.

Oh I paid too little attention to that bit thanks for pointing it out, :) HotKeySet, IsPressed or a Keyboard hook will be the way to go then ;) The help-file has great examples of each.
Link to comment
Share on other sites

ok well it seemed easier to just put the cases in as the function and scrap the buttons. the GUI now serves no purpose except to show me that it is running. i also added an exit func so if i accidentally have it running and try to use the number pad, i can close out of it at any time :)

thanks for the help!

here is the final if anyone wants to check it out:

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
$Form1 = GUICreate("GUI", 401, 201, 723, 228)
GUISetBkColor(0x0000FF)
GUISetState(@SW_SHOW)
Global $PixelCheck1, $PixelCheck2, $PixelCheck3, $NewCheck
HotKeySet("{NUMPAD1}", "Button1")
HotKeySet("{NUMPAD2}", "Button2")
HotKeySet("{NUMPAD3}", "Button3")
HotKeySet("{NUMPAD9}", "CloseTabs")
HotKeySet("`", "HomeTab")
HotKeySet("{1}", "Tab1")
HotKeySet("{2}", "Tab2")
HotKeySet("{3}", "Tab3")
HotKeySet("{NUMPAD7}", "ExitProgram")

Func ExitProgram()
    Exit
EndFunc

Func HomeTab()
    MouseClick("left", 200, 18, 1, 0)
    MouseMove(870, 919, 0)
EndFunc


Func Tab1()
    MouseClick("left", 435, 18, 1, 0)
    MouseMove(1460, 400, 0)
EndFunc

Func Tab2()
    MouseClick("left", 695, 18, 1, 0)
    MouseMove(1460, 400, 0)
EndFunc

Func Tab3()
    MouseClick("left", 935, 18, 1, 0)
    MouseMove(1460, 400, 0)
EndFunc


Func CloseTabs()
    MouseClick("left", 1106, 18, 1, 0)
    MouseClick("left", 857, 18, 1, 0)
    MouseClick("left", 606, 18, 1, 0)
EndFunc

Func Button1()

            MouseClick( "left", 977, 855, 3) ; Select Item
            Sleep(250)
            MouseClick( "right", 977, 855) ;right click
            SLeep(250)
            Send("c") ;copy
            $PixelCheck2 = PixelCheckSum(40, 950, 100, 960)
            MouseClick( "left", 1815, 300)
            Sleep(1000)
            While $PixelCheck2 <> $NewCheck
                $NewCheck = PixelCheckSum(40, 950, 100, 960)
                Sleep(500)
            WEnd
            MouseClick( "right", 842, 256) ; right click search box
            Sleep(250)
            Send("p") ;
            Sleep(250)
            Send("{ENTER}")

EndFunc

Func Button2()
    $PixelCheck1 = PixelCheckSum(40, 950, 100, 960)
            MouseClick( "left", 1076, 854, 3)
            Sleep(250)
            MouseClick( "right", 1076, 854)
            Sleep(250)
            Send("c")
            Sleep(250)
            MouseClick( "left", 1815, 300)
            Sleep(1000)
            While $PixelCheck1 <> $NewCheck
                $NewCheck = PixelCheckSum(40, 950, 100, 960)
                Sleep(500)
            WEnd
            MouseClick( "right", 842, 256) ; right click in search box
            Sleep(250)
            Send("p") ; paste
            Sleep(250)
            Send("{ENTER}") ; press search
            Sleep(250)
            MouseClick( "left", 230, 16) ;~ Home Tab
            Sleep(250)
            MouseClick( "left", 876, 853, 3)
            Sleep(250)
            MouseClick( "right", 876, 853)
            Sleep(250)
            Send("c")
            Sleep(250)
            $PixelCheck2 = PixelCheckSum(40, 950, 100, 960)
            Sleep(250)
            MouseClick( "left", 1815, 300)
            Sleep(1000)
            While $PixelCheck2 <> $NewCheck
                $NewCheck = PixelCheckSum(40, 950, 100, 960)
                Sleep(500)

            WEnd
            MouseClick( "right", 842, 256)
            Sleep(250)
            Send("p")
            Sleep(250)
            Send("{ENTER}")

EndFunc

Func Button3()
    $PixelCheck1 = PixelCheckSum(40, 950, 100, 960)
            MouseClick( "left", 1113, 855, 3)
            Sleep(250)
            MouseClick( "right", 1113, 855)
            Sleep(250)
            Send("c")
            MouseClick( "left", 1815, 300)
            Sleep(1000)
            While $PixelCheck1 <> $NewCheck
                $NewCheck = PixelCheckSum(40, 950, 100, 960)
                Sleep(500)
            WEnd
            MouseClick( "right", 842, 256)
            Sleep(250)
            Send("p")
            Sleep(250)
            Send("{ENTER}")
            Sleep(250)
            MouseClick( "left", 230, 16) ;~ Home Tab
            Sleep(250)
            MouseClick( "left", 977, 855, 3)
            Sleep(250)
            MouseClick( "right", 977, 855)
            SLeep(250)
            Send("c")
            $PixelCheck2 = PixelCheckSum(40, 950, 100, 960)
            MouseClick( "left", 1815, 300)
            Sleep(1000)
            While $PixelCheck2 <> $NewCheck
                $NewCheck = PixelCheckSum(40, 950, 100, 960)
                Sleep(500)
            WEnd
            MouseClick( "right", 842, 256)
            Sleep(250)
            Send("p")
            Sleep(250)
            Send("{ENTER}")
            Sleep(250)
            MouseClick( "left", 230, 16) ;~ Home Tab
            Sleep(500)
            MouseClick( "left", 847, 855, 3)
            Sleep(500)
            MouseClick( "right", 847, 855)
            SLeep(500)
            Send("c")
            $PixelCheck3 = PixelCheckSum(40, 950, 100, 960)
            MouseClick( "left", 1815, 300)
            Sleep(1000)
            While $PixelCheck3 <> $NewCheck
                $NewCheck = PixelCheckSum(40, 950, 100, 960)
                Sleep(500)
            WEnd
            MouseClick( "right", 842, 256)
            Sleep(250)
            Send("p")
            Sleep(250)
            Send("{ENTER}")

EndFunc

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

    EndSwitch
WEnd
Edited by Kidney
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...