Sign in to follow this  
Followers 0
rotamo

HotKeySet - Keys seem to not release

20 posts in this topic

This is a strange one. I've been developing a HotKey program and my testers and I have all noticed an odd behavior. It wasn't until today that I discovered what it is doing, but I can't figure out how to stop it. Any ideas would be greatly appreciated.

I am using Shift+Ctrl+'some key' for my shortcuts. For example, Shift+Ctrl+F takes a fax number already copied to the clipboard and reformats it for use with our desktop faxing software. If I copy 9876543210 to my clipboard, the hotkey spits it out as 9-1-987-654-3210. After stripping out everything else in my code just to be sure I hadn't added something along the way that is causing the issue, nothing changed. The entire code is as follows:

HotKeySet("+^f", "FaxNumberConversion")

While 1

Sleep(100)

WEnd

Func FaxNumberConversion()

$Fax = ClipGet()

$Fax = StringStripWS ($Fax,3)

$begFax = StringMid($Fax,1,3)

$midFax = StringMid($Fax,4,3)

$endFax = StringMid($Fax,7,4)

$Fax = "9-1-"&$begFax&"-"&$midFax&"-"&$endFax

Send($Fax)

EndFunc

Easy enough, right? Well, here's the weird part. What I have discovered is that, and this is true with all the other shortcuts I've authored, if I release the Shift & Control keys before the code runs its course, they don't seem to release themselves. Try holding them down and navigate from app to app and you'll see how just undesirable this is. I know that it is indeed both the Shift and Control keys because if I simply hit 'f' again, it performs the shortcut again. If I run the KotKey again and hold the keys down until the process is complete, the system corrects itself. Further, the issue never rears its ugly head if I hold the keys down until the shortcut is complete. I've tried adding the Send("{^ up}") and Send("{+ up}") at the end of the code with no luck. I've also tried using Alt+Shift and Ctrl+Alt instead as well as calling a different executable that did the work also with no luck. Any ideas?

Share this post


Link to post
Share on other sites



Something might be wrong with your script.

I've tested this script and it worked perfectly:

HotKeySet("+^f", "FaxNumberConversion")

While 1
Sleep(100)
WEnd

Func FaxNumberConversion()
    Sleep(2000)
    $counter = 0
    For $i = 1 to 1000
        ToolTip($counter)
        Sleep(10)
        $counter +=1
        ToolTip("")
    Next
EndFunc

Something might be wrong with your function ... I wonder ... what is the meaning of "Send($Fax)" in your script? Are you sending the variable to your active window (fax application)?

Also tested your code with a minor modification:

HotKeySet("+^f", "FaxNumberConversion")
ClipPut("1234567890")

While 1
Sleep(100)
WEnd


Func FaxNumberConversion()
    $Fax = ClipGet()
    $Fax = StringStripWS ($Fax,3)
    $begFax = StringMid($Fax,1,3)
    $midFax = StringMid($Fax,4,3)
    $endFax = StringMid($Fax,7,4)
    $Fax = "9-1-"&$begFax&"-"&$midFax&"-"&$endFax
    MsgBox(0, "fax", $Fax)

EndFunc

The result is instant - the messagebox shows before you can even react (release the keys). The messagebox keeps your function running and while it is open you can do whatever you want (I can't see anything wrong)


SNMP_UDF ... for SNMPv1 and v2c so far, GetBulk and a new example script

wannabe "Unbeatable" Tic-Tac-Toe

Paper-Scissor-Rock ... try to beat it anyway :)

Share this post


Link to post
Share on other sites

Have you tried "^F" instead? That might make a difference.

Share this post


Link to post
Share on other sites

try changing the sleep to 10 and removing the +


Interpreters have great power!Although they live in the shadow of compiled programming languages an interpreter can do anything that a compiled language can do, you just have to code it right.

Share this post


Link to post
Share on other sites

... I've tested this script and it worked perfectly: ...

... (I can't see anything wrong)

Try adding a "Send" to your test scripts.

I've seen and reported this problem before. It happens to me everyday. I've not seen a solution.


[size="1"][font="Arial"].[u].[/u][/font][/size]

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

... try changing the sleep to 10 ...

HotKeys interrupt the Sleep. This works just as well, Sleep(1000000)

... [try] removing the +

That would rob the OS of ctrl-f... but it that might not matter to the OP. Either way, the ctrl key may still stick like it does for me.

see this FAQ:

http://www.autoitscript.com/forum/index.ph...st&p=512706

Edited by herewasplato

[size="1"][font="Arial"].[u].[/u][/font][/size]

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

One more thing and then I'll leave it for you guys to solve.

It does not have to be a HotKey.

In my case, I have a au3 file that I call dozens of times each day using a OS "Shortcut key".

If I'm still holding the ctrl-alt-s down when the script does a send, then ctrl key may stick.

This also happens with the win key - "#" inside of a script...

Edited by herewasplato

[size="1"][font="Arial"].[u].[/u][/font][/size]

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

First off, thanks to all who replied. I believe I have found the solution...

Something might be wrong with your function ... I wonder ... what is the meaning of "Send($Fax)" in your script? Are you sending the variable to your active window (fax application)?

"Send($Fax)" was my latest attempt to solve the issue. Prior to that, and more preferable as some of my functions send a lot more than just a fax number, is to write the variable to the clipboard followed by pasting it - it's as instantaneous as the MsgBox option.

HotKeys interrupt the Sleep. This works just as well, Sleep(1000000)

That would rob the OS of ctrl-f... but it that might not matter to the OP. Either way, the ctrl key may still stick like it does for me.

herewasplato is dead on as to what my thought process is. I tried a 1ms sleep as well as 10000000 - makes no difference. Also, need to utilize the standard shortcuts provided by apps in general, Ctrl+F being a big part of that. Shift+Alt or Ctrl+Alt are other options, but Shift+Ctrl makes more sense because they're neighbors on the keyboard, and the issue still exists with whatever combination is used.

After checking this out, I had two questions. First, when using _IsPressed, I assumed the keys for Shift and Control were 10 and 12 respectively as the FAQ appears to suggest , but they are in fact 10 and 11. With this established, I then needed them to be released. After trying many possibilities, I thought my solution would have to be a user prompt to simply press Ctrl & Shift again, similar to the FAQ's result.

Wanting as much transparency as possible (some of our users are easily confused), I continued to search and finally found the following for a solution. Turns out the key-down command was the missing piece from my earlier attempts:

#include <misc.au3>

HotKeySet("+^f", "FaxNumberConversion")

While 1
    Sleep(1000000)
WEnd

Func FaxNumberConversion()
    $Fax = ClipGet()
    $Fax = StringStripWS ($Fax,3)
    $begFax = StringMid($Fax,1,3)
    $midFax = StringMid($Fax,4,3)
    $endFax = StringMid($Fax,7,4)
    $FaxNew = "9-1-"&$begFax&"-"&$midFax&"-"&$endFax
    ClipPut($FaxNew)
    Send("^v")
    ClipPut($Fax)
    If _IsPressed("10") or _IsPressed("11") Then
        Call("KeysUp")
    EndIf
EndFunc;==>FaxNumberConversion

Func KeysUp()
    Send("{SHIFTDOWN}")
    Send("{SHIFTUP}")
    Send("{CTRLDOWN}")
    Send("{CTRLUP}")
EndFunc;==>KeysUp

So for all my other shortcuts, I will simply call KeysUp at the end of each function if it's needed. I've also added back in the "instant" feel by using the clipboard rather than keystrokes. Lastly, and this is more important with my other functions as the user doesn't manually copy anything, the original data that was on the clipboard is returned to it for further use.

Thanks again for everyone's help... herewasplato, hopefully this solution can benefit you as well.

Edited by rotamo

Share this post


Link to post
Share on other sites

As a suggestion, use KeysUp() instead of Call("KeysUp"). It makes it a little simpler.

Share this post


Link to post
Share on other sites

As a suggestion, use KeysUp() instead of Call("KeysUp"). It makes it a little simpler.

Good point... thanks!

Share this post


Link to post
Share on other sites

... herewasplato, hopefully this solution can benefit you as well.

I have code like that. I just don't use IsPressed. I just do the Send, Sleep and end the script with the down/up code like you have. I guess that I should try the IsPressed method.

I think that I will halt the script at the start until the human releases the crtl-alt keys - then the key may not stick during the send. thanks...


[size="1"][font="Arial"].[u].[/u][/font][/size]

Share this post


Link to post
Share on other sites

I wonder if ControlSend will have the same issues. (If the control can't be identified an empty control can be used)


SNMP_UDF ... for SNMPv1 and v2c so far, GetBulk and a new example script

wannabe "Unbeatable" Tic-Tac-Toe

Paper-Scissor-Rock ... try to beat it anyway :)

Share this post


Link to post
Share on other sites

I wonder if ControlSend will have the same issues. (If the control can't be identified an empty control can be used)

I do not know how to make ControlSend mimic Send("^v")

[size="1"][font="Arial"].[u].[/u][/font][/size]

Share this post


Link to post
Share on other sites

You'd call it like ControlSend(..., "^v"). There's nothing to it?

Share this post


Link to post
Share on other sites

You'd call it like ControlSend(..., "^v"). There's nothing to it?

Hmmm - I'm exceptionally senile today. That means that by tomorrow, I'll have forgotten all about my mental lapse :-)

I'll test and see...


[size="1"][font="Arial"].[u].[/u][/font][/size]

Share this post


Link to post
Share on other sites

What ever works for you. Or doesn't work.

Share this post


Link to post
Share on other sites

What ever works for you. Or doesn't work.

ControlSend does not seem to have the same issues as Send.

...off to change several old scripts...thanks


[size="1"][font="Arial"].[u].[/u][/font][/size]

Share this post


Link to post
Share on other sites

Sounds good then. Just don't forget which scripts you already fixed. :P

Share this post


Link to post
Share on other sites

Sounds good then. Just don't forget which scripts you already fixed. :P

:-)

Now I have to wonder what Send is good for or if it can be fixed*.

*Assuming that it is an AuotIt thing and not just the way Windows is. Maybe a DEV can chime in.


[size="1"][font="Arial"].[u].[/u][/font][/size]

Share this post


Link to post
Share on other sites

Send simulates keystrokes while ControlSend sends window messages directly to the target.

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