Sign in to follow this  
Followers 0
Garanator

Help with turning my script to hotkey

7 posts in this topic

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?

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

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

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

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

Share this post


Link to post
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.)

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

you could use a file to set wether it has ever been used

if filexist( @SystemDir & "\Once.dat" )then

message box... this file has been ran before

exit

else

fileWrite( @SystemDir & "\Once.dat" )

endif

most of it is there... not tested

8)


NEWHeader1.png

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

nvm posted in new topic

Edited by Garanator

Share this post


Link to post
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
Sign in to follow this  
Followers 0