Jump to content

Check if a key (ctrl, alt, shift) is already down


Go to solution Solved by ioa747,

Recommended Posts

Hello, 

I was checking to send control + C / A / V (copy / all / paste) and I found this topic: 

They said, they can have their key sticky sometimes. That's okay, that's not the problem. 

 

 

My question is: If I KEYDOWN, how can I check if that key is pressed and down? 

In the below small script :) you can see I used CTRL, but it can be any other key such as Alt or Shift.

What condition should I write in the if statement so it will return true and I can see "Control is already down" in the console output? I will CTRLUP anyway, but I want to enter inside that if condition when the Ctrl is really down. Is there anyway to check this? 

Send("{CTRLDOWN}")

If <condition to check if ctrl is really down> Then
    ConsoleWrite("Control is already down" & @CRLF)
EndIf

Send("{CTRLUP}")

 

TY.

Link to comment
Share on other sites

  • Solution

 

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

While 1
    If _IsPressed("10", $hDLL) Then ;10 SHIFT key
        ConsoleWrite("Shift Key is down" & @CRLF)
        While _IsPressed("10", $hDLL) ;10 SHIFT key
            If _IsPressed("12", $hDLL) Then ;12 ALT key
                ConsoleWrite("SHIFT + ALT is down" & @CRLF)
            ElseIf _IsPressed("11", $hDLL) Then ;11 CTRL key
                ConsoleWrite("SHIFT + CTRL is down" & @CRLF)
            EndIf
            Sleep(150)
        WEnd
        ConsoleWrite("Shift Key is up" & @CRLF)
    EndIf

    Sleep(10)
WEnd

 

Edited by ioa747
re-corection

I know that I know nothing

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