Sign in to follow this  
Followers 0
incubusor

Hold a key down until another key is released?

2 posts in this topic

#1 ·  Posted (edited)

#include <Misc.au3>
#include <MsgBoxConstants.au3>

Local $hDLL = DllOpen("user32.dll")

While 1

   ; if shift is pressed while w is already pressed
   If _IsPressed("10", $hDLL) And _IsPressed("57",$hDLL) Then

      ; hold down shift until w is released
      Do
         Send("{SHIFTDOWN}")
      Until Not _IsPressed("57", $hDLL)
      Send("{SHIFTUP}")

   ; exit application loop when F11 is pressed
   ElseIf _IsPressed("7A", $hDLL) Then
      ExitLoop
      MsgBox($MB_SYSTEMMODAL, "Test Script", "Cya later! Application is closing!")
   EndIf

WEnd

The idea is: When Shift is pressed while W is already held down, hold shift down until W is released.

The Do Loop doesn't seem to be working correctly. Having Send("{shift down}") in there seems to make the W key not function at all either.

Edited by incubusor

Share this post


Link to post
Share on other sites

Example

#include <Misc.au3>

HotKeySet("{F11}", "Done")
HotKeySet("+w", "Start")

Global $hDLL = DllOpen("user32.dll")
Global $fStart = False

While 1

    ;when either of the keys is released check if only shift is released.
    If _IsPressed('10', $hDLL) = 0 And _IsPressed('57', $hDLL) And $fStart Then

        Send("{SHIFTDOWN}")
        While _IsPressed('57', $hDLL)
            Sleep(10)
        WEnd
        Send("{SHIFTUP}")

        $fStart = False
        HotKeySet("+w", "Start")

    EndIf

WEnd

Func Done()
    DllClose($hDLL)
    Exit
EndFunc

Func Start()
    $fStart = True
    HotKeySet("+w")
    Send("W")
EndFunc

Regards :)


My code:

PredictText: Predict Text of an Edit Control Like Scite. Remote Gmail: Execute your Scripts through Gmail. StringRegExp:Share and learn RegExp.

Run As System: A command line wrapper around PSEXEC.exe to execute your apps scripts as System (LSA). Database: An easier approach for _SQ_LITE beginners.

MathsEx: A UDF for Fractions and LCM, GCF/HCF. FloatingText: An UDF for make your text floating. Clipboard Extendor: A clipboard monitoring tool. 

Custom ScrollBar: Scroll Bar made with GDI+, user can use bitmaps instead. RestrictEdit_SRE: Restrict text in an Edit Control through a Regular Expression.

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