Jump to content

Keys stay pressed with Send


Recommended Posts

Hello together,

i wrote a little script to simplify the generation of a software documentation.

Take some words out of a word table, bring it in another sequence and paste it to another document.

Here is what i did:

;ClipPut()

Send("{TAB}{SHIFTDOWN}{TAB}{SHIFTUP}{CTRLDOWN}c{CTRLUP}")

;$Param = ClipGet()

Send("{TAB}{CTRLDOWN}c{CTRLUP}")

;$Desc = ClipGet()

Send("{TAB}{CTRLDOWN}c{CTRLUP}")

;$Unit = ClipGet()

Send("{TAB}{CTRLDOWN}c{CTRLUP}")

;$Range = ClipGet()

ClipGet has been commented out.

My problem is that after my script is run the keys for CTRL and ALT stay pressed.

Sending {CTRLUP} and {ALTUP} (which i don't use !!!) at the end does not solve the problem.

My keyboard layout is ok and the problem even exist if i run the script in the notepad window.

To fix the problem i have to press CTRL and then ALT on the keyboard.

I searched this forum but did not find a solution.

Regards

Sascha

Link to comment
Share on other sites

I have often answered this question.

Why does the Ctrl key get stuck down after I run my script?

It could equally be the Shift or the Alt key.

If you use Send in a script and you have a problem with keys being stuck down then Send is the most likely culprit. A similar problem can occur with BlockInput. The solution is generally quite simple. If there is a key like Shfit or Alt held down at the start of the Send sequence, but that key is released by the time the Send sequence finishes then the key will get 'stuck' down. As an example of a solution, you could replace the Send function in your script with the _SendEx function below.

;Send the string $ss after the Shift Alt and Ctrl keys are released. Optionally give a warning after 1 sec if any of those keys still down.
;Requires misc.au3 to be included in the script for the _IsPressed function.
Func _SendEx($ss,$warn = "")
    Local $iT = TimerInit()
    
    While _IsPressed("10") Or _IsPressed("11") Or _IsPressed("12")
        if $warn <> "" and TimerDiff($iT) > 1000 Then
            MsgBox(262144, "Warning", $warn)
        EndIf
      sleep(50)
    WEnd
    Send($ss)
    
EndFunc;==>_SendEx
Link to comment
Share on other sites

$ss is what you want to send:

_SendEx("hello!")

Func _SendEx($ss,$warn = "")
    Local $iT = TimerInit()
    
    While _IsPressed("10") Or _IsPressed("11") Or _IsPressed("12")
        if $warn <> "" and TimerDiff($iT) > 1000 Then
            MsgBox(262144, "Warning", $warn)
        EndIf
      sleep(50)
    WEnd
    Send($ss)
    
EndFunc;==>_SendEx
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...