Sign in to follow this  
Followers 0
Tomb

adding timer between pressing hokeys

11 posts in this topic

hi. i am creating this rpg about my dog, its called Toby's Quest. i have all of the hotkeys set up, just if you hold them down, or press them to fast, the images move to fast and they flash badly. is there some way i can set a delay of like 500 miliseconds before being able to press a hotkey again. I tried adding sleep(500) in the hotkey functions, but that becomes very buggy. i just want the functions to sleep like 500 miliseconds before they can be used again. is there some way i can do this?

Share this post


Link to post
Share on other sites



Disable the Hotkey at the start of your function and then reset it at the end using a sleep if required.



Get Beta versions Here Get latest SciTE editor Here AutoIt 1-2-3 by Valuater - A great starting point.

Time you enjoyed wasting is not wasted time ......T.S. Elliot
Suspense is worse than disappointment................Robert Burns
God help the man who won't help himself, because no-one else will...........My Grandmother

Share this post


Link to post
Share on other sites

Disable the Hotkey at the start of your function and then reset it at the end using a sleep if required.

how would i disable a hotkey?

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

Parameters

key The key combination to use as the hotkey. Same format as Send().

function [optional] The name of the function to call when the key is pressed. Not specifying this parameter will unset a previous hotkey.

Ie

HotKeySet("{ESC}")

Edited by BigDod


Get Beta versions Here Get latest SciTE editor Here AutoIt 1-2-3 by Valuater - A great starting point.

Time you enjoyed wasting is not wasted time ......T.S. Elliot
Suspense is worse than disappointment................Robert Burns
God help the man who won't help himself, because no-one else will...........My Grandmother

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

Parameters

key The key combination to use as the hotkey. Same format as Send().

function [optional] The name of the function to call when the key is pressed. Not specifying this parameter will unset a previous hotkey.

Ie

HotKeySet("{ESC}")

so if this were the normal function

Func _ScrollUp();UP

GUICtrlSetState($pic1, $GUI_HIDE)
GUICtrlSetState($pic2, $GUI_HIDE)
GUICtrlSetState($pic3, $GUI_HIDE)
GUICtrlSetState($pic4, $GUI_HIDE)

    $GetPos = ControlGetPos($GUI, "", $background)
    ControlMove($GUI, "", $background, $GetPos[0], $GetPos[1]+5)

GUICtrlSetState($pic1, $GUI_SHOW)
EndFunc

actually im still confused

Edited by Tomb616

Share this post


Link to post
Share on other sites

HotKeySet("{ESC}", '_ScrollUp')

Func _ScrollUp();UP
GUICtrlSetState($pic1, $GUI_HIDE)
GUICtrlSetState($pic2, $GUI_HIDE)
GUICtrlSetState($pic3, $GUI_HIDE)
GUICtrlSetState($pic4, $GUI_HIDE)

    $GetPos = ControlGetPos($GUI, "", $background)
    ControlMove($GUI, "", $background, $GetPos[0], $GetPos[1]+5)

GUICtrlSetState($pic1, $GUI_SHOW)
HotKeySet("{ESC}")
Sleep(500)
HotKeySet("{ESC}", '_ScrollUp')
EndFunc

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

so if this were the normal function

Func _ScrollUp();UP

GUICtrlSetState($pic1, $GUI_HIDE)
GUICtrlSetState($pic2, $GUI_HIDE)
GUICtrlSetState($pic3, $GUI_HIDE)
GUICtrlSetState($pic4, $GUI_HIDE)

    $GetPos = ControlGetPos($GUI, "", $background)
    ControlMove($GUI, "", $background, $GetPos[0], $GetPos[1]+5)

GUICtrlSetState($pic1, $GUI_SHOW)
EndFunc

actually im still confused

Here is one way you could do it

HotKeySet("1", "hotkeys");set all hot keys to the same function
HotKeySet("2", "hotkeys")
;more hot keys
Global $HotOK = True;the hot keys will work

Func hotkeys()
    If Not $HotOK Then Return
    $HotOK = False
    AdlibEnable("releaseme", 500);set for the delay you want
    Switch @HotKeyPressed
        Case "1"
            func1;whatever you function is
            
        Case "2"
            func2
    EndSwitch

;might be better to put the ADlibEnable here so that the delay starts from when the func called ends
EndFunc ;==>hotkeys

Func Releaseme ()
    $HotOK = True
    AdlibDisable()
EndFunc

EDIT: added note about moving the position of AdlibEnable

Edited by martin

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

Share this post


Link to post
Share on other sites

if i press a hotkey, the only hotkeys there really are so far are {up}, {down}, {left}, {right}, can i disable all of the hotkeys for maybe 500 miliseconds, then reenable them? that is my main goal here.

Share this post


Link to post
Share on other sites

if i press a hotkey, the only hotkeys there really are so far are {up}, {down}, {left}, {right}, can i disable all of the hotkeys for maybe 500 miliseconds, then reenable them? that is my main goal here.

The example I gave does that, at least it stops the hot keys having any effect for 500 mS after any one is pressed.

There are other ways to do it but I would need to know what you didn't like about the way I've suggested already before I could suggest another.


Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

Share this post


Link to post
Share on other sites

The example I gave does that, at least it stops the hot keys having any effect for 500 mS after any one is pressed.

There are other ways to do it but I would need to know what you didn't like about the way I've suggested already before I could suggest another.

yours confused me lol.

i keep rereading it, but im missing out on what is going on there.

Share this post


Link to post
Share on other sites

actually nevermind i worked out a solution with BMP2RGN.dll

thanks for help guys

it doesnt flash at all now :D

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