Jump to content

Help, HotKeySet()


Guest BL@(K-R34P3R
 Share

Recommended Posts

Guest BL@(K-R34P3R

I'm writing a sneak trainer bot for Morrowind. I'm trying to make it so that F1 will start the script, and F2 will stop it. For some reason, when I start the script, it will automatically start going, even without the hotkey press... Also, It won't stop when I press F2. Can someone please tell me what's wrong? I have looked over helpfile many times. Thanks.

;Raises the sneak skill in Morrowind. 
;Use:
;Start Morrowind game save, go to a shop where people are, and face the corner, then start the script.
;F1 - starts script, F2 - stops script
$i = 1
HotKeySet("{F1}", "SneakFunc")
HotKeySet("{F2}", "FuncStop")
SneakFunc()
Func SneakFunc()
   WinActivate("Morrowind")
   WinSetState("Morrowind", "", @SW_MAXIMIZE)
   While $i > 0
      Send("{CTRLDOWN}")
      Send("{w down}")
      $i = $i + 1
   Wend
EndFunc
FuncStop()
Func FuncStop()
   Exit 0
EndFunc
Link to comment
Share on other sites

Guest BL@(K-R34P3R

I was just thinking... In my while loop... Do I even need to do the:

$i = $i + 1

? Or will the $i = 1 part at top be enough?

Edited by BL@(K-R34P3R
Link to comment
Share on other sites

Guest BL@(K-R34P3R

To create an infinite loop, you can use a non-zero number as the expression.

Thanks.

Edited:

;Raises the sneak skill in Morrowind. 
;Use:
;Start Morrowind game save, go to a shop where people are, and face the corner, then start the script.
;F1 - starts script, F2 - stops script
HotKeySet("{F1}", "SneakFunc")
HotKeySet("{F2}", "FuncStop")
SneakFunc()
Func SneakFunc()
   WinActivate("Morrowind")
   WinSetState("Morrowind", "", @SW_MAXIMIZE)
   While 1
      Send("{CTRLDOWN}")
      Send("{w down}")
   Wend
EndFunc
FuncStop()
Func FuncStop()
   Exit 0
EndFunc

Question still stands... Any ideas Valik? Are my hotkeys messed up or something?

Link to comment
Share on other sites

I'm writing a sneak trainer bot for Morrowind. I'm trying to make it so that F1 will start the script, and F2 will stop it. For some reason, when I start the script, it will automatically start going, even without the hotkey press... Also, It won't stop when I press F2. Can someone please tell me what's wrong? I have looked over helpfile many times. Thanks.

;Raises the sneak skill in Morrowind. 
;Use:
;Start Morrowind game save, go to a shop where people are, and face the corner, then start the script.
;F1 - starts script, F2 - stops script
HotKeySet("{F1}", "SneakFunc")
HotKeySet("{F2}", "FuncStop")
While 1
Sleep(2147483647);
WEnd
;SneakFunc() <=== you are calling sneakfunc to be run, that is why it is starting

Func SneakFunc()
   WinActivate("Morrowind")
   WinSetState("Morrowind", "", @SW_MAXIMIZE)
   While 1
      Send("{CTRLDOWN}")
      Send("{w down}")
   Wend
EndFunc

Func FuncStop()
   Exit
EndFunc

<{POST_SNAPBACK}>

You cannot use hotkeys with some games. I editted your code. Edited by KnowledgeSponge
Link to comment
Share on other sites

Theres a huge logic error. You call SneakFunc() right off to get to the While loop so your script doesn't die, correct? But obviously, this also starts your other code as well. The helpfile example for HotKeySet does exactly what you want.

Edit: And F1/F2 are probably bound by the game. Try something more arbitrary.

Edited by Valik
Link to comment
Share on other sites

Guest BL@(K-R34P3R

Woa, I just learned a lot... I was under the impression, that to make a function in AutoIt, you need to declare it like this:

FuncName() ; I THOUGHT I NEEDED THIS!!!!

Func FuncName()

EndFunc

Well, I'm really stupid. I will edit and try again, thanks for help Valik, and KnowledgeSponge.

Link to comment
Share on other sites

Guest BL@(K-R34P3R

While 1
Sleep(2147483647);
WEnd

Just curious, but why would I sleep it for forever? ... I'm not sure why that is in there?

Link to comment
Share on other sites

While 1
Sleep(2147483647);
WEnd

Just curious, but why would I sleep it for forever? ... I'm not sure why that is in there?

<{POST_SNAPBACK}>

Just to keep the script running with least possible cpu cycles used. If you took this out the script would just run and exit immediately. You gotta direct it to run some code or it goes bye bye. Edited by KnowledgeSponge
Link to comment
Share on other sites

Guest BL@(K-R34P3R

Question:

Doesn't the sleep command pause the script??? I never knew that a script could run with sleep on.

Link to comment
Share on other sites

Guest BL@(K-R34P3R

Thanks. I just edited the script a little:

;Raises the sneak skill in Morrowind. 
;Use:
;Start Morrowind game save, go to a shop where people are, and face the corner, then start the script.
;F1 - starts script, F2 - stops script
HotKeySet("{F2}", "SneakFunc")
HotKeySet("{F3}", "FuncStop")

StartFunc()
Func StartFunc()
WinActivate("Morrowind")
WinSetState("Morrowind", "", @SW_MAXIMIZE)
EndFunc

Func SneakFunc()
   While 1
      Send("{CTRLDOWN}")
      Send("{w down}")
   Wend
EndFunc
Func FuncStop()
   Exit 0
EndFunc

Problem is, even after assigning the script to unused hotkeys, it still won't work. Now, it won't start the script at F2 press, and I have no idea if F3 works because it wont start in the first place! So do you think this is because the game doesn't allow hotkeys?

Link to comment
Share on other sites

Dude, that looks to me like it is gonna execute the startup func and then exit. If that script is staying open after you run morrowind, then I'm missing something. Once it sets the windows state, it's leaving the function. What are you telling it to do at that point? Nothing, so it's gonna exit.

Link to comment
Share on other sites

Guest BL@(K-R34P3R

Oh... I thought it would keep running... Would this work?

;Raises the sneak skill in Morrowind. 
;Use:
;Start Morrowind game save, go to a shop where people are, and face the corner, then start the script.
;F1 - starts script, F2 - stops script
HotKeySet("{F2}", "SneakFunc")
HotKeySet("{F3}", "FuncStop")

WinActivate("Morrowind")
WinSetState("Morrowind", "", @SW_MAXIMIZE)

Func SneakFunc()
   While 1
      Send("{CTRLDOWN}")
      Send("{w down}")
   Wend
EndFunc
Func FuncStop()
   Exit 0
EndFunc

Without the StartFunc() Function? I thought that in order for it to run commands like WaitWinActive and whatever, it needed to be in a function, or am I wrong?

Link to comment
Share on other sites

Oh... I thought it would keep running... Would this work?

;Raises the sneak skill in Morrowind. 
;Use:
;Start Morrowind game save, go to a shop where people are, and face the corner, then start the script.
;F1 - starts script, F2 - stops script
HotKeySet("{F2}", "SneakFunc")
HotKeySet("{F3}", "FuncStop")

WinActivate("Morrowind")
WinSetState("Morrowind", "", @SW_MAXIMIZE)

Func SneakFunc()
   While 1
      Send("{CTRLDOWN}")
      Send("{w down}")
   Wend
EndFunc
Func FuncStop()
   Exit 0
EndFunc

Without the StartFunc() Function? I thought that in order for it to run commands like WaitWinActive and whatever, it needed to be in a function, or am I wrong?

<{POST_SNAPBACK}>

No that will do the same thing. What code is going to be executed after WinSetState? It's not running those functions unless you call them with either a hotkey or say func(). I posted code already that would work. If it didn't work it's due to the fact the autoit is not reading the hotkey presses.
Link to comment
Share on other sites

Guest BL@(K-R34P3R

New, working script:

;Raises the sneak skill in Morrowind. 
;Use:
;Start Morrowind game save, go to a shop where people are, and face the corner, then start the script.
;To exit the script, exit Morrowind. Then Right click the system tray icon and click "Exit".

StartFunc()
Func StartFunc()
WinActivate("Morrowind")
WinSetState("Morrowind", "", @SW_MAXIMIZE)
EndFunc

SneakFunc()
Func SneakFunc()
   While 1
      Send("{CTRLDOWN}")
      Send("{w down}")
   Wend
EndFunc

Any suggestions on how to improve it?

Link to comment
Share on other sites

I said once that the example in the helpfile for HotKeySet does exactly what you want. (By exactly, I mean that you have to insert your code for Morrowind, but other than that, the code is what you want).

Link to comment
Share on other sites

Guest BL@(K-R34P3R

Valik, I am looking at the Helpfile right now... Can you PLEASE be more specific, if it is possible, I would like to assign it to a hotkey, or hotkeys. If you can help, please don't hold back! I just looked at it again, and I am still not seeing anything different..

Link to comment
Share on other sites

Similar to the helpfile example:

;Raises the sneak skill in Morrowind.
;Use:
;Start Morrowind game save, go to a shop where people are, and face the corner, then start the script.
;To exit the script, exit Morrowind. Then Right click the system tray icon and click "Exit".

Global $bPaused = 1, $alive = 1

; Redefine these to whatever you want
Global $hkToggle = "!t"
Global $hkEnd = "!s"

HotKeySet($hkToggle, "Toggle")
HotKeySet($hkEnd, "Stop")
WinActivate("Morrowind")
WinSetState("Morrowind", "", @SW_MAXIMIZE)

While $alive
    If $bPaused Then
        Sleep(100)
    Else
        Send("{CTRLDOWN}")
        Send("{w down}")    
    EndIf
WEnd
; You can place any cleanup code after the While loop

; Function definitions
Func Toggle()
    $bPaused = Not $bPaused; If 0, becomes 1, if 1, becomes 0
EndFunc; Toggle()

Func Stop()
    $alive = 0
EndFunc; Stop()

If the hotkeys don't work, change them to something else. If you can't find any keys that work, then it means Morrowind is doing something to prevent them from working.

Edit: Fixed typo in code.

Edited by Valik
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...