Jump to content

Recommended Posts

Posted

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

Posted

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.

Posted

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

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:

Posted

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

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

Posted

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

Posted

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

Posted

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

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

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.

Posted

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

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...