Jump to content

Different Hotkeys For Key Up/ Key Down?


Recommended Posts

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.

Link to comment
Share on other sites

  • Moderators

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
Link to comment
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?
Link to comment
Share on other sites

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
Link to comment
Share on other sites

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]

Link to comment
Share on other sites

  • Moderators

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

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

  • Moderators

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!

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

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