Sign in to follow this  
Followers 0
psgame_freak

How to get the last button pressed by user?

36 posts in this topic

Let say I have a hotkey set on 'A'. Now, if user presses right arrow keythen 'A' it will perform the function. If user presses left arrow key then 'A' it will perform a different function?

So

A then Right arrow = do something

A then Left arrow = do something else

Share this post


Link to post
Share on other sites



Let say I have a hotkey set on 'A'. Now, if user presses right arrow keythen 'A' it will perform the function. If user presses left arrow key then 'A' it will perform a different function?

So

A then Right arrow = do something

A then Left arrow = do something else

Something like this?

HotKeySet("{RIGHT}", "SetRightModifier")
HotKeySet("{LEFT}", "SetLeftModifier")
HotKeySet("a", "ModifiedAction")

Global $Modifier = ""

While 1
        Sleep(100)  
Wend 
    
Func ModifiedAction()     
        If $Modifier = "Right" then
            FunctionA()
        ElseIf $Modifier = "Left" then 
            FunctionB()
        Else
            FunctionC()
        EndIf 
        
        $Modifier = "" 
EndFunc

Func SetRightModifier()
        $Modifier = "Right"
EndFunc

Func SetLeftModifier()
        $Modifier = "Left"
EndFunc 

Func FunctionA()
    MsgBox(0,"", "Function A")
EndFunc

Func FunctionB()
    MsgBox(0,"", "Function B")
EndFunc

Func FunctionC()
    MsgBox(0,"", "Function C")
EndFunc

Let me know if this helps.

Share this post


Link to post
Share on other sites

That gave me the idea, but what about a record the last word that was typed?

Thank you

Share this post


Link to post
Share on other sites

i think i'll be needing this too :whistle:

making a keychanger for a game, but i need to to wait for a keypress and then return the keypress.

so is there any way to make a loop with hex ?? (for the _IsPressed function)

i think this might help the fellow here also


*If u thought life couldn't get worse, u meet me *<guy> What would you give my little sister to unzip ?<friend> 10 bucks<guy> No, i mean like Winzip...

Share this post


Link to post
Share on other sites

Hey Functions work according to the combination of keys pressed.

Now my problem is I want right button to also go right(its normal use) at the same time assigning "right" to modifier variable.

When I go:

Func SetRightModifier()

$Modifier = "right"

Send("{RIGHT}")

EndFunc

Func SetLeftModifier()

$Modifier = "left"

Send("{LEFT}")

EndFunc

I get a recursive error because it calls itself again :whistle:

Share this post


Link to post
Share on other sites

Func _GetKey()
    while 1
    for $i = 1 to 165
        if _IsPressed(Hex($i,2)) Then
            return $i
        EndIf
    Next
    wend
EndFunc

this waits for a user to press a button, then returns the button pressed


*If u thought life couldn't get worse, u meet me *<guy> What would you give my little sister to unzip ?<friend> 10 bucks<guy> No, i mean like Winzip...

Share this post


Link to post
Share on other sites

Could you tell me how that works?

When do I call that function?

Whats in the _IsPressed function?

Thank you

Share this post


Link to post
Share on other sites

Could you tell me how that works?

When do I call that function?

Whats in the _IsPressed function?

Thank you

His code works because it takes every number between 1 and 165, and gets what the mean in hex, and then says

if the hex of that number is equal to the button pressed, then return that value

and _IsPressed is part of 'Misc.au3' so make sure you put

#Include <Misc.au3>

at the top of your script

Share this post


Link to post
Share on other sites

Here's what my Misc.au3 says:

#include-once

; ------------------------------------------------------------------------------
;
; AutoIt Version: 3.0
; Language:       English
; Description:    Functions that assist with Intenet.
;
; ------------------------------------------------------------------------------


;===============================================================================
;
; Function Name:    _Iif()
; Description:      Perform a boolean test within an expression.
; Parameter(s):     $f_Test     - Boolean test.
;                   $v_TrueVal  - Value to return if $f_Test is true.
;                   $v_FalseVal - Value to return if $f_Test is false.
; Requirement(s):   None.
; Return Value(s):  One of $v_TrueVal or $v_FalseVal.
; Author(s):        Dale (Klaatu) Thompson
;
;===============================================================================
Func _Iif($f_Test, $v_TrueVal, $v_FalseVal)
   If $f_Test Then
      Return $v_TrueVal
   Else
      Return $v_FalseVal
   EndIf
EndFunc

No _IsPressed.

And when I replace _IsPressed with _Iif i get: Incorrect number parameters in function call

Share this post


Link to post
Share on other sites

Here's what my Misc.au3 says:

#include-once

; ------------------------------------------------------------------------------
;
; AutoIt Version: 3.0
; Language:       English
; Description:    Functions that assist with Intenet.
;
; ------------------------------------------------------------------------------
;===============================================================================
;
; Function Name:    _Iif()
; Description:      Perform a boolean test within an expression.
; Parameter(s):     $f_Test     - Boolean test.
;                   $v_TrueVal  - Value to return if $f_Test is true.
;                   $v_FalseVal - Value to return if $f_Test is false.
; Requirement(s):   None.
; Return Value(s):  One of $v_TrueVal or $v_FalseVal.
; Author(s):        Dale (Klaatu) Thompson
;
;===============================================================================
Func _Iif($f_Test, $v_TrueVal, $v_FalseVal)
   If $f_Test Then
      Return $v_TrueVal
   Else
      Return $v_FalseVal
   EndIf
EndFunc

No _IsPressed.

And when I replace _IsPressed with _Iif i get: Incorrect number parameters in function call

Are you running beta?

and if so, is this misc.au3 in the BETA include folder;

C:/Program Files/Autoit3/Beta/Include

Share this post


Link to post
Share on other sites

Come one, anyone? This is my last problem then my program will be up and running.

Share this post


Link to post
Share on other sites

your running the production

download beta at the bottom of the downloads page

Share this post


Link to post
Share on other sites

the one that says BETA


*If u thought life couldn't get worse, u meet me *<guy> What would you give my little sister to unzip ?<friend> 10 bucks<guy> No, i mean like Winzip...

Share this post


Link to post
Share on other sites

#16 ·  Posted (edited)

Bah, still doesn't work +.+

Global $Modifier = ""

HotKeySet("{RIGHT}", "SetRightModifier")
HotKeySet("{LEFT}", "SetLeftModifier")


Func _GetKey()
    while 1
    for $i = 1 to 165
        if _IsPressed(Hex($i,2)) Then
            return $i
        EndIf
    Next
    wend
EndFunc

;-----

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   ;==>_IsPressed

;------

Func SetRightModifier()
    $Modifier = "right"
    _GetKey()
EndFunc


Func SetLeftModifier()
    $Modifier = "left"
    _GetKey()
EndFunc

;---

I don't get errors this time. But it's not returning right (no pun intended).

Edited by psgame_freak

Share this post


Link to post
Share on other sites

what do you want your program todo then ??


*If u thought life couldn't get worse, u meet me *<guy> What would you give my little sister to unzip ?<friend> 10 bucks<guy> No, i mean like Winzip...

Share this post


Link to post
Share on other sites

I want it so when I press Right key, it will assign right to $Modifier and move cursor to right. But right now, it's just assigning "right" to $Modifier but not moving the cursor to the right.

I tried

Func SetRightModifier()
    $Modifier = "right"
    send("{RIGHT}")
EndFunc

But this does not work because it calls itself again.

Share this post


Link to post
Share on other sites

But this does not work because it calls itself again.

Thats why you use "_IsPressed", it doesn't steal keys

Global $Modifier = ""

If _IsPressed(##) then;Right arrow
SetRightModifier()
Endif


If _IsPressed(##) then;Left arrow
SetLeftModifier()
Endif

Func _GetKey()
    while 1
    for $i = 1 to 165
        if _IsPressed(Hex($i,2)) Then
            return $i
        EndIf
    Next
    wend
EndFunc

;-----

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   ;==>_IsPressed

;------

Func SetRightModifier()
    $Modifier = "right"
    _GetKey()
EndFunc


Func SetLeftModifier()
    $Modifier = "left"
    _GetKey()
EndFunc

Share this post


Link to post
Share on other sites

What do I put in the (##)?

Where can I find the hex table of keys?

Thanks alot for the replies and bearing with me :whistle:

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