Jump to content

Help with turning my script to hotkey


Recommended Posts

I want my script only to run when a hotkey is pressed how would i go about doing that?

HotkeySey("{F7}, "?")

Script I want to run only when f7 is pushed

Func ?

Also to not have to double post is there a way to make the script only run once. What I mean by that is the script will run but then like gets an error no matter what if ran again?

Link to comment
Share on other sites

maybe like this

; Press Esc to terminate script, Pause/Break to "pause"

Global $Paused, $T = 0
HotKeySet("{PAUSE}", "TogglePause")
HotKeySet("{ESC}", "Terminate")
HotKeySet("{F9}", "ShowMouse") 

;;;; Body of program would go here;;;;
While 1
    If $T = 1 Then
        $pos = MouseGetPos()
        MsgBox(0,"RUNNING", "This Script is now running")
        $T = 2
    EndIf
Sleep(10)
WEnd
;;;;;;;;

Func TogglePause()
    $Paused = NOT $Paused
    While $Paused
        sleep(100)
        ToolTip('Script is "Paused"',0,0)
    WEnd
    ToolTip("")
EndFunc

Func Terminate()
    Exit 0
EndFunc

Func ShowMouse()
    If $T = 0 Then
        $T = 1
        Return
    EndIf
    If $T = 2 Then
        MsgBox(0,"ERROR", "This Script will only run once")
        Return
    EndIf

EndFunc

8)

Edited by Valuater

NEWHeader1.png

Link to comment
Share on other sites

yea, valuater's is right on it.

Anotherwords though:

;Explanation: HotKeySet("{KEY}", "FUNCTION NAME")

HotKeySet("{F9}", "ShowMouse")

;Explanation: FUNCTION NAME WITH () BELOW!

Func ShowMouse()

;PLACE YOUR SCRIPT HERE

EndFunc ;Ends the Function

;Explanation: This loads what needs to be loaded, then pauses it (keeps it running so you can hit hotkeys)

While 1

WEnd

Edited by CrewXp
Link to comment
Share on other sites

Small modification to Crew's code:

While 1
    Sleep(0x7FFFFFFF)
WEnd

It's important to have a Sleep() in the loop or else your CPU usage will fly through the roof and slow everything else down. (The 0x7FFFFFFF is just a very large number in hex notation -- the larger the number, the less often the loop has to be looped and therefore the less unnecessary CPU usage.)

Link to comment
Share on other sites

In this that would mean that the program can be ran only once everytime you run it but you can just re run to have it be ran again. So is it possible to make it only run once forever? unless you have the sorce code?

Func ShowMouse()

If $T = 0 Then

$T = 1

Return

EndIf

If $T = 2 Then

MsgBox(0,"ERROR", "This Script will only run once")

Return

EndIf

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