Sign in to follow this  
Followers 0
crislivinitup

Send key problem

10 posts in this topic

I am using an autoIt program to send hotkeys (registered as hotkeys by another program) and I am having an odd problem. The key combination I am trying to send is Ctrl + insert.

Send("^{insert}")

;~ Have also tried the following:
;~ Send("{LCTRL DOWN}")
;~ Send("{insert down}")
;~ Send("{insert up}")
;~ Send("{LCTRL UP}")

It seems to work the first time, then I find that the ctrl or the insert key sticks. I.e. after the program has fired due to recieving the hotkey, I can press insert and it will fire again since the ctrl key hasn't been released. Any ideas or suggestions?

Share this post


Link to post
Share on other sites



I had the same problem yesterday. Left ctrl stuck pressed down but I thought scite was messing things up because of the memory leak of some things I was trying so I didn't pay attention.

I would like to see what is going on as well

Share this post


Link to post
Share on other sites

Maybe after you do the

Send("^{insert}")

you could do an

if _ispressed(11) then

send("^")

endif

if _ispressed(2D) then

send("{insert}")

endif

 

I can't quite remember offhand, but I believe just hitting the keys again would get them unstuck, so something like this may work.


010101000110100001101001011100110010000001101001011100110010000

001101101011110010010000001110011011010010110011100100001

My Android cat and mouse game
https://play.google.com/store/apps/details?id=com.KaosVisions.WhiskersNSqueek

We're gonna need another Timmy!

Share this post


Link to post
Share on other sites

Hmmm, doesn't seem to work, I've tried sending various other keys afterwards (with the send command) and it didn't seem to null out the sticky control

Share this post


Link to post
Share on other sites

hmm, that's how I've fixed the issue in my scripts. (I'm at work now and can look through what I have)

So I'm not sure where to go from there.


010101000110100001101001011100110010000001101001011100110010000

001101101011110010010000001110011011010010110011100100001

My Android cat and mouse game
https://play.google.com/store/apps/details?id=com.KaosVisions.WhiskersNSqueek

We're gonna need another Timmy!

Share this post


Link to post
Share on other sites

I would suggest bringing up the On-Screen Keyboard and watching it while your script runs, to determine if the key is actually sticking or if it is something else.


√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites

Send() is not very reliable, but _WinAPI_Keybd_Event() never go wrong, so:

Func Press_CTRL_C_Macross($t = 8)
    _WinAPI_Keybd_Event(0x11, 0) ; CTRL Down
    _WinAPI_Keybd_Event(0x43, 0) ; c Down
    Sleep($t)
    _WinAPI_Keybd_Event(0x43, 2) ; c Up
    _WinAPI_Keybd_Event(0x11, 2) ; CTRL Up
EndFunc   ;==>Press_CTRL_C_Macross

you can customise this for you needs

Share this post


Link to post
Share on other sites

Hey thanks guys for the advice. I tried Iczer's solution and it seemed to work! The snippet was very easy to use :)

Share this post


Link to post
Share on other sites

I came across this problem again in another script of mine and I figured out a great way to get past it that I thought I would share. The problem seems to happen when a send command is in a function that is activated by a hotkey. Moreover, it happens when the send command executes before the user has a chance to lift his finger off of the hotkey keys. I haven't tested all of the keys with which this happens, but the best solution I found is as follows:

#include <Misc.au3>

Opt("WinTitleMatchMode", 2)

If WinExists("Todo") == 0 Then
    Run(@WindowsDir & "\Notepad.exe '" & "D:\Library\Documents\Todo.txt'", @WindowsDir)
    WinWait("Todo")
Else
    WinActivate("Todo")
EndIf

HotKeySet("^t", "dateStr")
HotKeySet("^q", "quit")

WinWaitClose("Todo")
Exit

Func dateStr()
    While(_IsPressed("11"))
        Sleep(50)
    WEnd
    If WinActive("Todo") Then
        Local $str
        $str = @YEAR & "/" & @MON & "/" & @MDAY & "/   " & @HOUR & ":" & @MIN
        Send($str)
    EndIf
EndFunc   ;==>dateStr

Func quit()
    Exit
EndFunc

I introduced a while loop check for the key being pressed so that the function (which is initiated by the hotkey) does not continue until the user has lifted his/her finger.

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

  • Similar Content

    • badcoder123
      By badcoder123
      Anyone know how to access the information circled in the photo?
       

    • AndreyS
      By AndreyS
      Dear developers and creators of the language, please explain to me why when pressing the combination Crtl + Shift + C from the 5th or the 10th time "sticks / sinks" Ctrl or Shift? And then you need to press Ctrl or Shift again to reset their triggering. I only need to use hot keys like in the example!
      The code is a small example. Its essence is that when a user in the editor selects any number and presses a combination, then it increases by 1. 
      Dim $x HotKeySet("+^c","Calc") While 1 Sleep(10000) WEnd Func Calc() Send("^c") Sleep(50) $x=ClipGet()+1 ClipPut($x) Send("^v") EndFunc I thought that in my program some kind of glitch was searching for a reason for a long time. And it turned out that apparently somehow the work of some functions used in the example is not compatible. 
      Tell me, please, what is the problem?
    • ur
      By ur
      If you observe in below code.
      Func _WinWaitActivate($title,$text,$timeout=$time_out) Logging("Waiting for "&$title&":"&$text) $dHandle = WinWait($title,$text,$timeout) if not ($dHandle = 0) then If Not WinActive($title,$text) Then WinActivate($title,$text) WinWaitActive($title,$text,$timeout) Else Logging("Timeout occured while waiting for the window...") Exit EndIf EndFunc WinActivate("Untitled - Notepad") $p = "Notallowed1!!" Send("{ENTER}{ENTER}{ENTER}{ENTER}"& $p &"{ENTER}create{SPACE}database{SPACE}"& $p &";{ENTER}") In the notepad if you observe, ! is missing in the text got.
       
      Is there way to get that also printed.
    • rawkhopper
      By rawkhopper
      Hello everyone,
      I have a script that is automating a piece of sluggish software.  I want to automate it with a bit of caution and I am not sure the best way to do it.  ControlSend works great most of the time.  If I have it enter 10 into a text box every once in a while it will enter 1 or 11 and then hit enter.
      To overcome this I use MouseClick to select the text I just entered and then see if it matches the string it was supposed to put in before it hits enter.  This seems to work but what I love about ControlSend is there is less room for human interaction messing it up.  
      Yes I could block input but I prefer not to do that (permissions).
      Is there a better way of doing this?  Any Help would be much appreciated.
      Anyway here is the snippet of the script in question:
      Func KVSend () WinActivate ( "Window", "" ) Local $WindowPos = WinGetPos("Window", "") If $kV < 30 Then WinActivate ( "Window", "" ) ControlClick ("Window", "", 1001) ;Click in Accel Voltage box Sleep (100) ControlSend ("Window", "", 1001, $kV) ; \ kV Sleep (100) MouseMove($WindowPos[0]+130,$WindowPos[1]+75,1) MouseClick($MOUSE_CLICK_LEFT) MouseClick($MOUSE_CLICK_LEFT) Send ("^c") Local $clip = ClipGet () If $clip = $kV Then ControlSend ("Window", "", 1001, "{ENTER}") ;Hit ENTER if value is correct Sleep (100) ControlClick ("Window", "", 1518) ;Lens Clear Else Send ("{BACKSPACE}") KVSend() ; If value is incorrect try again EndIf EndIf  
    • spuuunit
      By spuuunit
      This is what I'm trying to do: In Firefox, if you hold down CTRL + C for about 200ms, then press CTRL + T. This is my code:
      While WinActive(" - Mozilla Firefox") If _IsPressed("A2", $hDLL) And _IsPressed("43", $hDLL) Then $timer = TimerInit() While _IsPressed("A2", $hDLL) And _IsPressed("43", $hDLL) Sleep(10) $diff = TimerDiff($timer) If $diff > 200 Then Send("^{T}") While _IsPressed("A2", $hDLL) And _IsPressed("43", $hDLL) Sleep(10) WEnd EndIf WEnd EndIf WEnd The problem is that the CTRL key gets stuck down after Send("^{T}"). I found this, but what I understand that happens when I release, and that is not what I want. The "General unstuck method" did nothing.