Jump to content
Sign in to follow this  
crislivinitup

Send key problem

Recommended Posts

crislivinitup

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
AutID

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
kaotkbliss

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
crislivinitup

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
kaotkbliss

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
JLogan3o13

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!

How to get your question answered on this forum!

Share this post


Link to post
Share on other sites
Iczer

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
crislivinitup

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
crislivinitup

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  

  • Similar Content

    • ternal
      By ternal
      Hi,
      The FAQ proposed as a solution to keys getting stuck  to do this command
      ControlSend("", "", "", "text", 0) However this sends "text" to the last active control if I am not mistaken.I have tried this with
      controlsend("", "", "", "{altup}{shiftup}{ctrlup}", 0) This is already a lot better but still fails 1/10
      I cannot allow the script to send "text" to the last active control, and its a bit silly to let it send to somewhere where its harmless no?
      Are there any other methods of unstucking keys?
    • Fortitude
      By Fortitude
      Hello!
      I have made a program, that opens a folder, and then store the path ("C:\programFiles\etc") in a variable.
      Then i need to open the command panel as administrator, and write  in the stored path, and some other text.

      Can i somehow instantly copypaste the text i needed, instead of writing in the command panel with the Send commands?
       
      #RequireAdmin #include <MsgBoxConstants.au3> Global Const $sMessage = "Select a folder" ; Display an open dialog to select a file. Global $sFileSelectFolder = FileSelectFolder($sMessage, "") If @error Then MsgBox($MB_SYSTEMMODAL, "", "Nem választottál ki mappát!") Exit EndIf Global $Tiff_path = $sFileSelectFolder & "\TiffChecker_2_32" FileCopy( "C:\TiffChecker_2_32.exe" , $sFileSelectFolder) $CMD = $Tiff_path & " " & $sFileSelectFolder & " /s/d" Run("C:\WINDOWS\system32\cmd.exe") WinWaitActive("C:\WINDOWS\system32\cmd.exe") Send($CMD) Sleep(1000) Send("{ENTER}") sleep(1000) MsgBox(0,"Press OK", "Press OK to continue") FileCopy("C:\Tiffchecker.txt", $sFileSelectFolder) Also, how do i close the command panel, when the program is finished? (usually its under 1 second, so after the send i just put a Sleep function there)
    • Docfxit
      By Docfxit
      I would like to know if there is a way to make the send cmd send characters when using
      Graphical AutoIt Debugger By Stumpii,
      If Not WinActive("Setup - UltraVNC","Setup is preparing to install") Then WinActivate("Setup - UltraVNC","Setup is preparing to install") WinWaitActive("Setup - UltraVNC","Setup is preparing to install") Send("{ALTDOWN}f{ALTUP}") ;Finish The debugger when using step mode will execute the Send cmd line but the window doesn't receive the input.
      Thanks,
      Docfxit
    • PoojaKrishna
      By PoojaKrishna
      Hi friends,
      I'm trying to send SHIFTDOWN, to keep the Shift key pressed until I close the program or releases the key.
      Send ( "{SHIFTDOWN}") sleep(100) $text = InputBox("Shift key down", "Shift key is down. Type something: ") $ret = Msgbox(0,"", "Press and release shift key manually and select [Ok] to continue") $text = InputBox("Shift key up", "Shift key is released manually, now type something: ") Send ( "{SHIFTDOWN}") sleep(100) $text = InputBox("Shift key down Agin", "Shift key is pressed again, now type something: ") In the above program sequence,
      1. Send SHIFTDOWN from program, Works as we type in the text are in Capital letters
      2. Manually presses and releases the SHIFT button. SHIFT key is released as when we type, text is in small letters only.
      3. Again send SHIFTDOWN from program, but not working. When we type the letters are in small letters.
       
      If we send a SHIFTUP  before  sending the SHIFTDOWN again, then it is working correctly and the text appears in capital letters only. Can any one explain why this happens?
      Send ( "{SHIFTDOWN}") sleep(100) $text = InputBox("Shift key down", "Shift key is down. Type something: ") $ret = Msgbox(0,"", "Press and release shift key and select [Ok] to continue") $text = InputBox("Shift key up", "Shift key is released manually, now type something: ") Send ( "{SHIFTUP}") sleep(100) Send ( "{SHIFTDOWN}") sleep(100) $text = InputBox("Shift key down", "Shift key is pressed, now type something: ")  
      Thank you.
    • TheDcoder
      By TheDcoder
      Hello everyone, long time since I made a post in the H&S sub-forum
      I am working on a project where in a situation I would have to hold down an arrow key and release it in another statement/command, however when I wrote the code it isn't working exactly like I thought it would. Here is an example:
      Send("{UP down}") Sleep(10000) Send("{UP up}") This should hold the up arrow key for 10 seconds before releasing it again, but when I run this code the cursor in SciTE moves up only once
      If I hold the up arrow manually for 10 seconds it "repeats" and the cursor moves up several times until I release the key... Is this a known limitation of Send? Is there any other way I can accomplish this?
      Thanks for all the help and feedback in advance! TD
×