Jump to content
Sign in to follow this  
b0x4it

Some keys left pressed

Recommended Posts

b0x4it

I usually need to manipulate web page urls. So I have written this code in order to do it automatically:

#Include <Misc.au3>

Sleep(100)

While _IsPressed(10) or _IsPressed(11) or _IsPressed(12)
    Sleep(10)
WEnd

Opt("WinTitleMatchMode", 2)
;Opt("SendKeyDelay", 20)
If WinActive("Google Chrome") Then
    Send("!d")
    Send("^c")
    $Clipboard = ClipGet()
    If $Clipboard="" Then ; sometimes Alt+d + Ctrl+c does not work in first try, so I try one more time!
        Send("!d")
        Send("^c")
        $Clipboard = ClipGet()
    EndIf
    $Clipboard = StringReplace($Clipboard, "//", "\\")
    $Result = StringInStr($Clipboard, "/")
    $ClipboardLeft = StringLeft($Clipboard, $Result-1)
    $Clipboard = StringReplace($Clipboard, $ClipboardLeft, $ClipboardLeft&".ezproxy.xxx.myuniversity.edu")
    $Clipboard = StringReplace($Clipboard, "\\", "//")
    ClipPut($Clipboard)
    Send("!d")
    Send("^v")
    Send("{enter}")
Else
    MsgBox(0,"","Google Chrome is not the active windows!")
EndIf

    If _IsPressed(10) Then; the control key is #11
        MsgBox(0,"","Shift is still down!")
    EndIf
    
    If _IsPressed(11) Then; the control key is #11
        MsgBox(0,"","Ctrl is still down!")
    EndIf
    
    If _IsPressed(12) Then; the control key is #11
        MsgBox(0,"","Alt is still down!")
    EndIf

I do not want to have a code up and running all the time, so I used my application that is always running and is able to run anything using some hotkeys. I specified Shift+Ctrl+5 to run the above code when I am browsing a web page. It works properly. The only strange problem is that this code sometimes after manipulating the URL, leaves some keys in pressed mode including Shift, Ctrl, Alt or even Shift+Ctrl. I watched the keys using the on-screen keyboard of windows 7 (osk.exe). It clearly shows some of keys in pressed mode after pushing Shift+Ctrl+5 and running this code.

I tried different things to avoid multi-keypress occurrence like using Sleep between each Send or using _IsPressed, but it still happens. I made the Send("!d^c") commands separate in two different Send command with Sleep between them, with no luck!

I really appreciate if anyone has some suggestion.

Thanks

Edited by b0x4it

Share this post


Link to post
Share on other sites
Xandy

The problem I found seemed to be with the send() function. send() seemed to be holding the modifier key down.

I guess when the modifier was pressed and string was being sent by send().

Anyway _SendEx("keys") defined below, will wait to send("keys") until the modifier keys are not pressed... and if they're not pressed when you send they shouldn't get stuck in the down position.

I hope this makes sense, I hope it helps.

#include "misc.au3"
;_sendEx("keys");$keys will not be sent until CTRL, ALT, SHIFT are released back into the wild
Func _SendEx($keys)
    While _IsPressed("10") Or _IsPressed("11") Or _IsPressed("12")
      sleep(50)
    WEnd
    Send($keys)
EndFunc;==>_SendEx

Just add this func _SendEx($keys) above, and then change all your send( to _sendEx(

Edited by songersoft

Share this post


Link to post
Share on other sites
b0x4it

Thank you for your reply. I was thinking of something like this but then I told myself that it shouldn't be like this. I mean this simple problem should have been considered in the original Send function. So can we consider this problem as a bug?

Edited: Do I (or everybody) need to use this function instead of the original Send command?

Edited by b0x4it

Share this post


Link to post
Share on other sites
Xandy

I do not think it is in high priority, but I do not know such things either. It doesn't make me feel good that my users have to wait for all the keys to all be released to send a volume_up/down command. makes tapping the keys harder because I can't just hold ctrl, shift whatever and tap the hotkey to send the hotkey event, i gotta release em all, cause if I don't use _SendEx() than the mod keys get stuck. It's the only fix I got, and I am not going to cry.

I use Austin Beer's volume_control udf for this reason. but now we have media_forward/backward actions we can send with send(). And the problem comes back when scrolling through media, gotta release all the keys. Not that big of a deal with play/pause or stop though.

Edited by songersoft

Share this post


Link to post
Share on other sites
Xandy

Do I (or everybody) need to use this function instead of the original Send command?

by no means, _sendEx() forces you to release the keys. Plain send() does not. It is only when using the special mod symbols while sending(with send) that they get stuck and you need to use _sendEx() to prevent that.

Edited by songersoft

Share this post


Link to post
Share on other sites
Xandy

I'm not totally sure about how send errors, but you have all the tools I have. If you find out more be sure to let me know. : v)

Honestly Meatwad, I don't know where we came from.

but I do know how we're gonna die.

Edited by songersoft

Share this post


Link to post
Share on other sites
somdcomputerguy

This entry in the FAQ, 19 Why does the Ctrl key get stuck down after I run my script?, covers this issue. I have a very similar problem in one of my scripts, after Sending a {TAB}. I resolved it by adding this code after I Send the {TAB}.

Sleep(10)
Send("{CTRLDOWN}")
Sleep(10)
Send("{CTRLUP}")
Edited by somdcomputerguy

- Bruce /*somdcomputerguy */  If you change the way you look at things, the things you look at change.

Share this post


Link to post
Share on other sites
Xandy

I was unable to get locked Modifier key to release using this code:

Sleep(10)
Send("{CTRLDOWN}")
Sleep(10)
Send("{CTRLUP}")

However I came accross this code awhile back, sending this code will release the stuck modifier keys

ControlSend("", "", "", "text", 0)

even the "text" must be there !!

I don't know if you can change it to "frog" or not but sending no text will not work.

Edited by songersoft

Share this post


Link to post
Share on other sites
b0x4it

First I need to thank you all for your useful replies.

I tried :

ControlSend("", "", "", "text", 0)

it is not working in my case. Then I tried this:

Sleep(10)
Send("{CTRLDOWN}")
Sleep(10)
Send("{CTRLUP}")

Sleep(10)
Send("{SHIFTDOWN}")
Sleep(10)
Send("{SHIFTUP}")

Sleep(10)
Send("{ALTDOWN}")
Sleep(10)
Send("{ALTUP}")

it is working! :)

what now I do not understand is that why the developer of Autoit who is aware of this problem does not change the original Send command to fix the problem??

Share this post


Link to post
Share on other sites
Xandy

what now I do not understand is that why the developer of Autoit who is aware of this problem does not change the original Send command to fix the problem??

I imagine that it is very difficult thing, or it world be done. Tell you what tho, if you want to add the correct code to the autoit package. I'm sure alot of people will be thankful and ask for more.

can you use this method to send() a capital letter or SHIFT+key ?

Sleep(10)

Send("{SHIFTDOWN}")

Sleep(10)

Send("{SHIFTUP}")

I don't remember that working out for me. I should try it again.

Share this post


Link to post
Share on other sites
Blue_Drache

Send() sends the characters in a raw format. Ergo, if you Send("FOO") it outputs FOO... if you Send("bar") the output is bar. Modifier keys are only useful for when using such modifier would be pertinent to what your program needs to do.

"{SHIFTDOWN}foo{SHIFTUP}" is **NOT** the same as "FOO" to some programs.

Edited by Blue_Drache

Lofting the cyberwinds on teknoleather wings, I am...The Blue Drache

Share this post


Link to post
Share on other sites
somdcomputerguy

I just want to clarify something, that will maybe make 'why this happens' a little clearer. Now the entry in the FAQ states this,

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.

Now in my case, I'm not sending or controlsending any modifier-letter combinations yet still have a 'modifier key being stuck down' problem. I've narrowed it down to this bit of my code which sends a {TAB} right after I've manually done a ctrl-c, and the code I added to resolve this problem.

If ClipGet() <> "" Then
 $Spammer[0] = ClipGet()
  Send("{TAB 15}")
; following is how I 'release' the stuck down CTRL key
   Sleep(10)
  Send("{CTRLDOWN}")
   Sleep(10)
  Send("{CTRLUP}")
 EndIf

So, I'm still holding down the ctrl key when the script starts the send function, and releasing that key before the send function finishes, hence the 'stuck' problem. There are other ways to avoid this, which would mean that extra code isn't required, such as a sleep (say even as much as a quarter second), or a msgbox prompt.. Anyway, the 'why this happens' is important to understand, and I hope this longwinded explanation helps someone.


- Bruce /*somdcomputerguy */  If you change the way you look at things, the things you look at change.

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  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.