Jump to content

Little help with HotKeySet


Recommended Posts

I've never written a macro before so bare with whatever obvious mistakes I may have made here...

Basically the macro I have created so far just hits 4 keys (7,8,9,0) every 8.1 seconds. Works well enough, but I would like to modify this so that I can toggle this on and off with a hotkey.

What I've got so far:

HotKeySet("`","Twist")

Func Twist()

$loop = 0

While $loop = 0

Sleep(8100)

Send("7")

Sleep(100)

Send("8")

Sleep(100)

Send("9")

Sleep(100)

Send("0")

WEnd

EndFunc

I've tryed following the examples in the help file as best I could but can't get the hotkey to work. Can anyone point out what mistakes I have made here?

Link to comment
Share on other sites

  • Moderators

HotKeySet() has the exact example you're talking about in the help file.

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

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

Global $Paused
HotKeySet("{PAUSE}", "TogglePause")
HotKeySet("{ESC}", "Terminate")
HotKeySet("+!d", "ShowMessage") ;Shift-Alt-d

;;;; Body of program would go here;;;;
While 1
    Sleep(100)
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 ShowMessage()
    MsgBox(4096,"","This is a message.")
EndFunc

My Programs[list][*]Knight Media Player[*]Multiple Desktops[*]Daily Comics[*]Journal[/list]
Link to comment
Share on other sites

I assumed at first that the example was actually calling some kind of pause funtion, which was not very helpful for what I wanted to do. After reading responces and doing more testing I figured it out and got what I wanted, so thanks <_<

Global $Twist
HotKeySet("`", "ToggleTwist")


;;;; Body of program would go here;;;;
While 1
    Sleep(100)
WEnd
;;;;;;;;

Func ToggleTwist()
    $Twist = NOT $Twist
    While $Twist
            Send("7")
            Sleep(100)
            Send("8")
            Sleep(100)
            Send("9")
            Sleep(100)
            Send("0")
            Sleep(8100)
        WEnd
EndFunc
Link to comment
Share on other sites

ALMOST got what I wanted anyway <_<

The script worked fine while testing in notepad, but when I try to use it in the program (game actually) that I created it for, I get nothing. I inserted some WinActive code lines that.. sort of worked. If I hit the hotkey outside of the game, it would bring up the game and start the macro. But I can't start or stop the macro while the game is the active window.

Any ideas what could be going on here? Is it possible to get around this?

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