Jump to content

[Solved, Thx] Start / Stop button, and a loop


 Share

Recommended Posts

I'm back, sorry for the delay. A side note, you'll generally get friendlier people who might be more in a mood to help you if you don't constantly bump a topic- 24 hours is kind of the requested period around here.

My guess is that your game sets something within itself (like a hotkey or accelerator key) on F1...as likely as not, it's to prevent exactly what you're doing. (You may want to check the EULA of your game to make sure that bots aren't illegal ;) )

Try another hotkey, or checking for _IsPressed() on F1 in a loop instead of assigning a hotkey. (sorry, missed your note about this above)

Edit: it would help a lot of you'd answer the question I asked last- what does HotKeySet() return if your game has focus (and therefore the HotKeySet() appears to fail)?

Edited by james3mg
"There are 10 types of people in this world - those who can read binary, and those who can't.""We've heard that a million monkeys at a million keyboards could produce the complete works of Shakespeare; now, thanks to the Internet, we know that is not true." ~Robert Wilensky0101101 1001010 1100001 1101101 1100101 1110011 0110011 1001101 10001110000101 0000111 0001000 0001110 0001101 0010010 1010110 0100001 1101110
Link to comment
Share on other sites

I don't really know how to check what hotsetkey returns.

I mean, hotsetkey works, its role is to say :F1 now runs this function.

And not : If you press F1, I'll run this function.

So indeed, if I set :

if HotKeySet("{F1}", "FocusProg") Then
            MsgBox(0, "Ok !", "Works...") 
        Else 
            MsgBox(0, "... !", "Doesn't work...")
        EndIf

Once the gui appears, I'm spammed of "Works..." Msgbox (my hotsetkey function is in a while loop).

I suppose I havn't understood what you exactly meant.

@KaFu : I don't understand how to use it, even with an exemple. I guess I'm not skilled enough to use hooks.

But I'm pretty sure that it is what I need, so I can detect "F1 key is pressed" at any time.

Edit : I've managed to adapt an exemple I found in the help file. I guess it needs some more modifications.

#AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6

#include <WinAPI.au3>
#include <WindowsConstants.au3>

Opt('MustDeclareVars', 1)

Global $hHook, $hStub_KeyProc, $buffer = ""

_Main()

Func _Main()
    
    OnAutoItExitRegister("Cleanup")
    Local $hmod

    $hStub_KeyProc = DllCallbackRegister("_KeyProc", "long", "int;wparam;lparam")
    $hmod = _WinAPI_GetModuleHandle(0)
    $hHook = _WinAPI_SetWindowsHookEx($WH_KEYBOARD_LL, DllCallbackGetPtr($hStub_KeyProc), $hmod)
    
    While 1
        Sleep(10)
    WEnd
EndFunc

Func EvaluateKey($keycode)
    If ($keycode = 112) then ;F1
        $buffer &= Chr($keycode)
        Send("TEST")
    Else
        $buffer = ""
    EndIf
EndFunc

;===========================================================
; callback function
;===========================================================
Func _KeyProc($nCode, $wParam, $lParam)
    Local $tKEYHOOKS
    $tKEYHOOKS = DllStructCreate($tagKBDLLHOOKSTRUCT, $lParam)
    If $nCode < 0 Then
        Return _WinAPI_CallNextHookEx($hHook, $nCode, $wParam, $lParam)
    EndIf
    If $wParam = $WM_KEYDOWN Then
        EvaluateKey(DllStructGetData($tKEYHOOKS, "vkCode"))
    EndIf
    Return _WinAPI_CallNextHookEx($hHook, $nCode, $wParam, $lParam)
EndFunc

Func Cleanup()
    _WinAPI_UnhookWindowsHookEx($hHook)
    DllCallbackFree($hStub_KeyProc)
EndFunc
Edited by arkane
Link to comment
Share on other sites

First: you shouldn't put the HotKeySet() in a loop; it only has to be called once at the top of your script to set it, and once later on if you want to un-set it.

Getting the return value of the function is the same as any other return value; either:

ConsoleWrite(HotKeySet("{F1}","FocusProg"))
or
$ret=HotKeySet("{F1}","FocusProg")
ConsoleWrite($ret)
will write to the SciTE console the return from the HotKeySet function. If it's a 1, then it thinks it worked, and it would be significant if it returned a 1 and yet still didn't work. If it returns a 0, it means that it couldn't set the hotkey at all, so it's guarenteed that F1 will not call your function. 0 usually means that another program (like your game) has reserved the specified key as it's own hotkey already.
"There are 10 types of people in this world - those who can read binary, and those who can't.""We've heard that a million monkeys at a million keyboards could produce the complete works of Shakespeare; now, thanks to the Internet, we know that is not true." ~Robert Wilensky0101101 1001010 1100001 1101101 1100101 1110011 0110011 1001101 10001110000101 0000111 0001000 0001110 0001101 0010010 1010110 0100001 1101110
Link to comment
Share on other sites

No, you should base the movement of the character on the time elapsed, not the other way around (we did this in the 1980s and it sucked ).

Can you please give me more informations about how to do that ? I want it to work with the biggest precision possible.

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