Jump to content

_ispressed question


Alexxander
 Share

Recommended Posts

hi all

i have this mini script

#include <Misc.au3>
$dll = DllOpen("user32.dll")

func shift()
msgbox(0,"","shift")
While _IsPressed("10")
        Sleep(1)
WEnd

endfunc

Func a()
msgbox(0,"","a")
While _IsPressed("41")
        Sleep(1)
WEnd

endfunc

while 1
If _IsPressed("10", $dll) Then shift()
If _IsPressed("41", $dll) Then a()
WEnd

it is working fine when i press "a" or "shift"

but when i press "shift + a"  at the same second or i press shift and hold it down then "a" then release shift

when i do one from those i'll get a message box for the first key that is pressed

i want to run the two functions shift() and a() when the two keys are pressed together or shift holded

in my case i think that i can't get 2 message boxes at the same time but it is not working even if i used consolewrite for example

any ideas ?

Edited by Alexxander

Link to comment
Share on other sites

In this example pressing shift only runs shift() function, pressing "a" only runs a() function, pressing shift together with the "a" key runs shift() function and then the a() function,

If you only want the "a" plus shift key combination pressed, simply use JohnOne's advice  'If _IsPressed("10") And _IsPressed("41") Then'.

#include <Misc.au3>

Local $iFlag = 0

While 1
    Select
        Case _IsPressed("10"); Shift key
            While _IsPressed("10") ;Wait for shift key to be released.
                If _IsPressed("41") Then $iFlag = 1
                Sleep(10)
            WEnd
            If $iFlag = 0 Then
                shift()
            Else
                While _IsPressed("41") ;Wait for "a" key to be released.
                    Sleep(10)
                WEnd
                shift()
                a()
                $iFlag = 0
            EndIf
        Case _IsPressed("41") ; A key
            While _IsPressed("41") ;Wait for "a" key to be released.
                If _IsPressed("10") Then $iFlag = 1
                Sleep(10)
            WEnd
            If $iFlag = 0 Then
                a()
            Else
                While _IsPressed("10") ;Wait for shift key to be released.
                    Sleep(10)
                WEnd
                shift()
                a()
                $iFlag = 0
            EndIf
        Case _IsPressed("1B") ; Esc key
            ExitLoop
    EndSelect
    Sleep(10)
WEnd


Func shift()
    MsgBox(0, "", "shift", 3)
    While _IsPressed("10")
        Sleep(1)
    WEnd
EndFunc   ;==>shift

Func a()
    MsgBox(0, "", "a", 3)
    While _IsPressed("41")
        Sleep(1)
    WEnd
EndFunc   ;==>a
Edited by Malkey
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...