Sign in to follow this  
Followers 0
Autechre

Different Hotkeys For Key Up/ Key Down?

9 posts in this topic

Hello. A quick question about HotKey support. Regarding the HotKeySet function, is it possible to have two different functions for the same hotkey, with one function executed when the key is pressed and the other function executed when the key is depressed? Sort of like

HotKeySet("{a down}", "Enable")

HotKeySet("{a up}", "Disable")

If not, will there be possibility to maybe include such functionality in future released? Thanks in advance.

Share this post


Link to post
Share on other sites



Hello. A quick question about HotKey support. Regarding the HotKeySet function, is it possible to have two different functions for the same hotkey, with one function executed when the key is pressed and the other function executed when the key is depressed? Sort of like

HotKeySet("{a down}", "Enable")

HotKeySet("{a up}", "Disable")

If not, will there be possibility to maybe include such functionality in future released? Thanks in advance.

You could try something like this.

#include <Misc.au3>

While 1
    If _IsPressed(20) Then  
        While _IsPressed(20)
            ToolTip("You have the spacebar pressed.")
            Sleep(100)
        WEnd
        ToolTip("You released the spacebar.")
        Sleep(3000)
        ExitLoop
    EndIf
    Sleep(100)  
WEnd

Share this post


Link to post
Share on other sites

You could try something like this.

#include <Misc.au3>

While 1
    If _IsPressed(20) Then  
        While _IsPressed(20)
            ToolTip("You have the spacebar pressed.")
            Sleep(100)
        WEnd
        ToolTip("You released the spacebar.")
        Sleep(3000)
        ExitLoop
    EndIf
    Sleep(100)  
WEnd
Hrm, this looks like it might work, but the _IsPressed function doesn't seem to be defined in Misc.au3 nor is it part of the api set. Where is this function define?

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

u must have beta to use Misc.au3

http://www.autoitscript.com/autoit3/files/beta/autoit/

i dont think you need beta but it comes in beta or here it is

;===============================================================================
;
; Description:  _IsPressed
; Parameter(s): $s_hexKey - key to check for
;                       $v_dll = Handle to dll or default to user32.dll
;              
; User CallTip:   _IsPressed($s_hexKey[, $v_dll = 'user32.dll']) Check if key has been pressed. (required: <Misc.au3>)
; Return Value(s):  1 if true
;                           0 if false
; Author(s):      ezzetabi and Jon
;
;===============================================================================
Func _IsPressed($s_hexKey, $v_dll = 'user32.dll')
; $hexKey must be the value of one of the keys.
; _Is_Key_Pressed will return 0 if the key is not pressed, 1 if it is.
    Local $a_R = DllCall($v_dll, "int", "GetAsyncKeyState", "int", '0x' & $s_hexKey)
    If Not @error And BitAND($a_R[0], 0x8000) = 0x8000 Then Return 1
    Return 0
EndFunc  ;==>_Is_Key_Pressed
Edited by thatsgreat2345

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

Welcome to the forum.

The beta version of AutoIt has the _IsPressed User Defined Function (UDF) included in the file named misc.au3. You'll need the beta version to run the code that big_daddy posted above... or try this code:

;http://www.autoitscript.com/forum/index.php?s=&showtopic=5760
Opt("OnExitFunc", "endscript")

$dll = DllOpen("user32.dll")

While 1
    If _IsPressed("41") Then
        Do
            ToolTip("test")
            Sleep(99)
        Until Not _IsPressed("41")
    EndIf
    ToolTip("")
    Sleep(99)
WEnd

Func _IsPressed($hexKey)
    Local $aR
    $hexKey = '0x' & $hexKey
    $aR = DllCall("user32", "int", "GetAsyncKeyState", "int", $hexKey)
    If Not @error And BitAND($aR[0], 0x8000) = 0x8000 Then Return 1
    Return 0
EndFunc;==>_IsPressed

Func endscript()
    DllClose($dll)
EndFunc;==>endscript
Edit: too slow again........

Edit2: See this link for more info on the _IsPressed UDF:

http://www.autoitscript.com/forum/index.ph...&showtopic=5760

Edited by herewasplato

[size="1"][font="Arial"].[u].[/u][/font][/size]

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

And if you defintely want to use Hotkeys and Functions then maybe:

HotKeySet('a', 'A_Down')

While 1
    Sleep(100000)
WEnd

Func A_Down()
    $count = 0
    HotKeySet('a')
    While _IsPressed('41')
        $count += 1
        ToolTip($count, 0, 0)
        Sleep(10)
    WEnd
    A_Up()
    HotKeySet('a', 'A_Down')
EndFunc

Func A_Up()
    ToolTip('')
EndFunc

Func _IsPressed($s_hexKey, $v_dll = 'user32.dll')
    Local $a_R = DllCall($v_dll, "int", "GetAsyncKeyState", "int", '0x' & $s_hexKey)
    If Not @error And BitAND($a_R[0], 0x8000) = 0x8000 Then Return 1
    Return 0
EndFunc
Edit:

Forgot to add the _IsPressed() UDF, but others did anyway.

Edited by SmOke_N

[center]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.[/center]

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

SmOke_N,

Would still need beta

$count += 1

:-)

Edit - but cool code - just had to go there didn't ya

@Autechre,

Get beta :-)

It is stable.

Edited by herewasplato

[size="1"][font="Arial"].[u].[/u][/font][/size]

Share this post


Link to post
Share on other sites

SmOke_N,

Would still need beta

$count += 1

:-)

:think: , yeah, but if your not using Beta, it's like riding a bike with training wheels. Can be done, but just can't do all the tricks that make it fun!

[center]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.[/center]

Share this post


Link to post
Share on other sites

Thanks! I have it everything working great now.

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