Jump to content

Send key problem


Go to solution Solved by Iczer,

Recommended Posts

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?

Link to comment
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!

Link to comment
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!

Link to comment
Share on other sites

  • Moderators

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.

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
Share on other sites

  • Solution

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

Link to comment
Share on other sites

  • 4 weeks later...

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.

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

×
×
  • Create New...