Jump to content

modifier keys getting stuck down by HotKeySet


frew
 Share

Recommended Posts

Hello,

I'm struggling with not being able to get shift, ctrl, and alt key unstuck.

I read the FAQ and I don't get how to make that _SendEx solution work.

The single line of code solution thing there does not work either ie the ControlSend().

I set up a big HotKeySet script to sit there looping, watching for key presses, and it opens folders for me nicely, and runs programs, etc...but the sticking keys issue...too bad it's so tricky to get that to not happen.

I have a hotkey set up to open an au3. Then the au3 is supposed to send some keys, but since ctrl or shift, or alt are

stuck down (unless I physically press them on the keyboard), keys get send with ctrl (etc) being pressead down all the while.

Is this like a bug thing, requiring a workaround solution?

Thanks for any ideas.

frew

Link to comment
Share on other sites

Hello,

I'm struggling with not being able to get shift, ctrl, and alt key unstuck.

I read the FAQ and I don't get how to make that _SendEx solution work.

The single line of code solution thing there does not work either ie the ControlSend().

I set up a big HotKeySet script to sit there looping, watching for key presses, and it opens folders for me nicely, and runs programs, etc...but the sticking keys issue...too bad it's so tricky to get that to not happen.

I have a hotkey set up to open an au3. Then the au3 is supposed to send some keys, but since ctrl or shift, or alt are

stuck down (unless I physically press them on the keyboard), keys get send with ctrl (etc) being pressead down all the while.

Is this like a bug thing, requiring a workaround solution?

Thanks for any ideas.

frew

The _SendEx function is a work-around and it is supposed to be used instead of Send so that keys don't get stuck down. Is that what you did?

If you want to have a hot key which is set by having a combination of keys which includes a modifier key like Ctrl, then _Sendex will wait untill those keys are released and then send the keys. If you want the modifier added as part o fthe keys being sent then you must add that to the string to be sent.

If that doesn't help then I would need more information.

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

Thank you very much Martin.

I'm still trying to figure out how to make this work.

Here's what I have:

HotKeys_1.au3

HotKeySet("!{F1}", "_test")


While 1
    Sleep(1000)
WEnd


Func _test()
    ShellExecute(@AutoItExe, "script_1.au3", "C:\Program Files\AutoIt3")
EndFunc  ;==>_test

script_1.au3

Sleep(1000)
ShellExecute(@AutoItExe, "script_2.au3", "C:\Program Files\AutoIt3")
Sleep(2000)
Send("{Enter}");this Send seems to be where the alt key gets stuck down
               ;with this Send commented out, the alt key is not stuck down

script_2.au3

Sleep(1000)
Send("Hello.")

So with HotKeys_1.au3 running, I press Alt+F1 and script_1.au3 starts.

Script_1.au3 starts up script_2.au3.

If script_2.au3 has no Send, then the Alt key is not stuck down.

When script_2.au3 has the Send in it, the Alt key gets stuck down.

I think I'm missing something with the SendEx idea. I'm not sure if I need to create a string, or declare a variable, etc...or a syntax problem, where I'm not doing something quite right with it. Would I put the SendEx code in the top of script_2.au3 in my example? Then change every Send to _SendEx in script_2.au3?

Thank you so much for any ideas.

frew

Link to comment
Share on other sites

lol, Make a function that releases any possible pressed key. ;]

Sorry, I don't understand that. Did you test your idea with these scripts? I think that may not work.

Maybe it would. could you give an example please?

Thank you,

frew

Link to comment
Share on other sites

I wanted to use the _SendEx code, so I put it in the top of script_2.au3 like this:

#include <Misc.au3>

Func _SendEx($ss,$warn = "")
     Local $iT = TimerInit()
    
     While _IsPressed("10") Or _IsPressed("11") Or _IsPressed("12")
         if $warn <> "" and TimerDiff($iT) > 1000 Then
             MsgBox(262144, "Warning", $warn)
         EndIf
       sleep(50)
     WEnd
     Send($ss)
    
EndFunc;==>_SendEx



Sleep(1000)
ShellExecute(@AutoItExe, "script_2.au3", "C:\Program Files\AutoIt3")
Sleep(2000)
_SendEx("{Enter}");this Send seems to be where the alt key gets stuck down
               ;with this Send commented out, the alt key is not stuck down

That does not help, because I'm sure I need to modify something in this code. What do I need to change?

Thank you very much.

frew

Link to comment
Share on other sites

Thank you very much Martin.

I'm still trying to figure out how to make this work.

Here's what I have:

HotKeys_1.au3

HotKeySet("!{F1}", "_test")
  
  
  While 1
      Sleep(1000)
  WEnd
  
  
  Func _test()
      ShellExecute(@AutoItExe, "script_1.au3", "C:\Program Files\AutoIt3")
  EndFunc;==>_test

script_1.au3

Sleep(1000)
  ShellExecute(@AutoItExe, "script_2.au3", "C:\Program Files\AutoIt3")
  Sleep(2000)
  Send("{Enter}");this Send seems to be where the alt key gets stuck down
               ;with this Send commented out, the alt key is not stuck down

script_2.au3

Sleep(1000)
  Send("Hello.")

So with HotKeys_1.au3 running, I press Alt+F1 and script_1.au3 starts.

Script_1.au3 starts up script_2.au3.

If script_2.au3 has no Send, then the Alt key is not stuck down.

When script_2.au3 has the Send in it, the Alt key gets stuck down.

I think I'm missing something with the SendEx idea. I'm not sure if I need to create a string, or declare a variable, etc...or a syntax problem, where I'm not doing something quite right with it. Would I put the SendEx code in the top of script_2.au3 in my example? Then change every Send to _SendEx in script_2.au3?

Thank you so much for any ideas.

frew

All you have to do is use _SendEx and not Send

So instead of

Send("{Enter}");

use

_SendEx("{Enter}");

and make sure you add the _SendEx function to your script.

The problem you have is exactly why the _SendEx function was written. When you have a hotkey which uses Alt or Ctrl or shift which calls a function which uses Send then the Send starts before you have let go of the modifier keys so _SendEx simply waits untill they are released. There is an optional 2nd parameter to warn someone if they keep the modifier key held down.

Edited by martin
Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

and make sure you add the _SendEx function to your script.

Getting closer, but it's still not working yet. Bear with me please as I try to get this right.

Here's what I have now:

HotKeys_1.au3

HotKeySet("!{F1}", "_test")

While 1
    Sleep(1000)
WEnd

Func _test()
    ShellExecute(@AutoItExe, "script_1.au3", "C:\Program Files\AutoIt3")
EndFunc  ;==>_test

script_1.au3

#include <Misc.au3>

Func _SendEx($ss,$warn = "")
     Local $iT = TimerInit()
    
     While _IsPressed("10") Or _IsPressed("11") Or _IsPressed("12")
         if $warn <> "" and TimerDiff($iT) > 1000 Then
             MsgBox(262144, "Warning", $warn)
         EndIf
       sleep(50)
     WEnd
     Send($ss)
    
EndFunc;==>_SendEx


Sleep(1000)
ShellExecute(@AutoItExe, "script_2.au3", "C:\Program Files\AutoIt3")
Sleep(2000)
_SendEx("{Enter}")

script_2.au3

#include <Misc.au3>

Func _SendEx($ss,$warn = "")
     Local $iT = TimerInit()
    
     While _IsPressed("10") Or _IsPressed("11") Or _IsPressed("12")
         if $warn <> "" and TimerDiff($iT) > 1000 Then
             MsgBox(262144, "Warning", $warn)
         EndIf
       sleep(50)
     WEnd
     Send($ss)
    
EndFunc;==>_SendEx


Sleep(1000)
_SendEx("Hello.")

When I have HotKeys_1.au3 running, I press Alt+F1, that is, "!{F1}".

I have script_2.au3 open with cursor on a blank line and the word "Hello." shows up as expected.

Without doing a thing I press the letter "a", expecting to see the letter "a" show up, but instead

AutoIt Macro Generator shows up (indicating that the Alt key is still pressed down...(ie in Scite> Tools,

Alt+A starts up the AutoIt Macro Generator.

So what specifically do I need to do to the above three au3 to make it so when I press that final "a"

that just an "a" will show up...indicating that the Alt key is not pressed down still?

Thank you very much for any other ideas.

frew

Link to comment
Share on other sites

Thanks Authenticity, but I'm not able to get this code that you gave to work:

#include <Misc.au3>
Send('{ALTDOWN}')

While _IsPressed('12')
    Send('{ALTUP}')
    ConsoleWrite('Write' & @LF)
    Sleep(20)
WEnd

Did you happen to test this code that you gave with the three au3 that I put up?

Just curious if it worked for you.

I'd love to find a simple solution, but not quite there yet.

Thank you for your ideas to try.

frew

Link to comment
Share on other sites

You might want to rethink these lines of your code:

ShellExecute(@AutoItExe, "script_1.au3", "C:\Program Files\AutoIt3")

ShellExecute(@AutoItExe, "script_2.au3", "C:\Program Files\AutoIt3")

From the help file for @AutoItExe:

The full path and filename of the AutoIt executable currently running. For compiled scripts it is the path [and filename] of the compiled script.

I added the part in the brackets for clarity.

So - in your code for "HotKeys_1.au3"you are telling the operating system to run HotKeys_1.au3 again.

This part of that line of code is ignored:

, "script_1.au3", "C:\Program Files\AutoIt3"

You might want to glance at this thread ...

http://www.autoitscript.com/forum/index.php?showtopic=22531

... for ways to play with /AutoIt3ExecuteScript

As far as the problem of the keys sticking - you are in good hands with Martin.

BTW, UDF functions do not have to go at the top of a script ...

... but they can if you can stand the way that it looks :-)

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

Link to comment
Share on other sites

Thanks herewasplato.

I'm not sure what to do. I'll have to look into this a bit.

Everything as I have it is running the scripts as I want them to be run, so I'm reluctant to figure out another way to do it.

I start HotKeys_1.au3 and just let it run. It picks up the Alt+F1 and thus starts up script_1.au3, which then starts up script_2.au3. That's what I want to happen, so it appears to be working okay. I don't know if HotKeys_1.au3 ever runs with two of itself at the same time. Thanks for the ideas. I'll check into that a bit.

Seeya,

frew

Link to comment
Share on other sites

Thanks herewasplato.

I'm not sure what to do. I'll have to look into this a bit.

Everything as I have it is running the scripts as I want them to be run, so I'm reluctant to figure out another way to do it.

I start HotKeys_1.au3 and just let it run. It picks up the Alt+F1 and thus starts up script_1.au3, which then starts up script_2.au3. That's what I want to happen, so it appears to be working okay. I don't know if HotKeys_1.au3 ever runs with two of itself at the same time. Thanks for the ideas. I'll check into that a bit.

Seeya,

frew

frew, I tried your 3 scripts as you posted (with the _SendEx functions in script_1 and script_2).

They work ok for me and if I press 'a' I just get 'a' printed.

But when a script is running from SciTE the macro generator option isn't available for me. Anyway, the Alt key isn't stuck down so I wonder if your still running an old script without realizing it.

If I hold down the Alt key then the word 'hello' isn't printed until I let go of the Alt key which means that _SendEx is doing its job. Does that happen for you?

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

frew, I tried your 3 scripts as you posted (with the _SendEx functions in script_1 and script_2).

They work ok for me and if I press 'a' I just get 'a' printed.

But when a script is running from SciTE the macro generator option isn't available for me. Anyway, the Alt key isn't stuck down so I wonder if your still running an old script without realizing it.

If I hold down the Alt key then the word 'hello' isn't printed until I let go of the Alt key which means that _SendEx is doing its job. Does that happen for you?

Thanks so much Martin for checking this with the scripts I posted.

Yes, good idea to make sure I'm using the right au3...I double checked and I'm using the exact code I most recently posted...the one's with your _SendEx function in script_1.au3 and script_2.au3.

Unfortunatly I keep getting the same results where the alt key is down.

I pressed Alt+F1 while HotKeys_1.au3 is running, and that starts up script_2.au3, which then starts up script_3.au3.

"Hello." is printed, then, for example in another editor, Scite being closed during this latest test, and for example, I press an

'f' key and it opens the file menu, indicating the alt key is still down.

Okay, now for a little embarrassing note...I can only use AutoIt version 3. 2.12.1 because I'm on Windows 98SE (I know!)...

so would that make a difference? I mean, maybe the #include <Misc.au3> is not up to date? (by the way, I'm curious what the $ss variable is in your _SendEx function...because I do not see any value being given to $ss)...I'm new to a bunch of this...I was thinking maybe the value of the $ss variable was set in the Misc.au3..and since my Misc.au3 may be in need of updating...or not...

So I don't have it working yet. I do greatly appreciate your code and your help with this.

Thanks for any other ideas.

frew

Link to comment
Share on other sites

... I start HotKeys_1.au3 ...

If you run it as an au3, you will get one result.

If you run it as a compiled exe, you will get another result.

Try running this one line as an au3:

MsgBox(0, "", @AutoItExe)

Then run it as an exe.

When I tested your code, I tested it with HotKeys_1.au3 compiled. When compiled, it will just start itself over an over.

try these:

HotKeys_1.au3

#include <Misc.au3>

HotKeySet("!{F1}", "_test")

While 1
    Sleep(1000)
WEnd

Func _test()
    HotKeySet("!{F1}")
    While _IsPressed("10") Or _IsPressed("11") Or _IsPressed("12")
        Sleep(50)
        TrayTip("Waiting for...", "...Alt to be released", 10)
    WEnd
    TrayTip("", "", 10)
    RunWait(@AutoItExe & " /AutoIt3ExecuteScript script_1.au3")
    
    HotKeySet("!{F1}", "_test")
EndFunc   ;==>_testoÝ÷ Ù8^r^iº/{¥z-®éíéÞÆÛ®*mº{b*.­é^jÇ­à%µ»­¶ì¢z'yçm£
+ªèºwmë×îËb¢{®*mÕ«·jëh×6Sleep(1000)
Run(@AutoItExe & " /AutoIt3ExecuteScript script_2.au3")
Sleep(2000)
Send("{Enter}")oÝ÷ ÚÇ+vjíÚºÚ"µÍÛY
L
BÙ[
    ][ÝÒ[Ë][ÝÊ
Edited by herewasplato

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

Link to comment
Share on other sites

Thanks herewasplato, that looks promising. I'll try that now.

Here's a little thing I was just about to post before I saw your compiled ideas for me to try:

Also, I'm not sure why this is, but if I comment out the _SendEx in script_2.au3, then I can

change the _SendEx in script_3.au3 to Send (not _SendEx) and "Hello." prints fine, and I can go right into typing normally, ie no Alt key is being pressed down still.

So...what was that Send in script_2.au3 doing (the Send being now commented out in script_2.au3) that the Send in script_3.au3 is not doing? Hmmm...seems like the Send in script_3.au3 would cause a problem too, but it does not.

Just wanted to let you know this in case it could help figure out how to get things working here. Thanks.

Below is an example of what I refer to:

HotKeys_1.au3

HotKeySet("!{F1}", "_test")

While 1
    Sleep(1000)
WEnd

Func _test()
    ShellExecute(@AutoItExe, "script_1.au3", "C:\Program Files\AutoIt3")
EndFunc ;==>_test

script_1.au3 (Send/_SendEx commented out in this one)

#include <Misc.au3>

Func _SendEx($ss,$warn = "")
     Local $iT = TimerInit()
    
     While _IsPressed("10") Or _IsPressed("11") Or _IsPressed("12")
         if $warn <> "" and TimerDiff($iT) > 1000 Then
             MsgBox(262144, "Warning", $warn)
         EndIf
       sleep(50)
     WEnd
     Send($ss)
    
EndFunc;==>_SendEx


Sleep(1000)
ShellExecute(@AutoItExe, "script_2.au3", "C:\Program Files\AutoIt3")
Sleep(2000)
;_SendEx("{Enter}")

script_2.au3

#include <Misc.au3>

Func _SendEx($ss,$warn = "")
     Local $iT = TimerInit()
    
     While _IsPressed("10") Or _IsPressed("11") Or _IsPressed("12")
         if $warn <> "" and TimerDiff($iT) > 1000 Then
             MsgBox(262144, "Warning", $warn)
         EndIf
       sleep(50)
     WEnd
     Send($ss)
    
EndFunc;==>_SendEx


Sleep(1000)
Send("Hello.")

Thanks so much for any other ideas.

frew

Link to comment
Share on other sites

... (by the way, I'm curious what the $ss variable is in your _SendEx function...because I do not see any value being given to $ss)...I'm new to a bunch of this...I was thinking maybe the value of the $ss variable was set in the Misc.au3..and since my Misc.au3 may be in need of updating...or not...

The $ss is the string passed to the function _SendEx and is used for Send inside the function.
Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

try these

Nice...yes that works! Thanks so much herewasplato!

Okay, I have to rethink how I do things here with all this a bit.

Thanks so much for the code...I'll study that, very nice.

Not to jump right into more questions so soon, but I do wonder if

RunWait(@AutoItExe & " /AutoIt3ExecuteScript script_1.au3")

will find script_1.au3 if script_1.au3 is located way off in some other directory structure?

Also, the Traytip does not show up...may be my AutoIt version and OS?

Also, would I have to put that code for each function? I have a big list of HotKeySets in my HotKeySet main script.

(I could look into putting the function into a variable and using the variable to call the function?...I'm learning how to

do these things)

Again, very nice solution herewasplato, thank you so much.

frew

Link to comment
Share on other sites

The $ss is the string passed to the function _SendEx and is used for Send inside the function.

Thanks for clearing that up Martin.

I greatly appreciate all your help with this issue. Your solution is a wonderful solution for most users I'm sure.

My setup is probably such that it does not allow your solution here.

I'd be interested in any other ideas you have about how to get it to work here, but I think there must be some limitation on

my end, due probably to my current OS and my version of AutoIt...since your exact duplication of my process works on your end.

Thank you so much for your help and ideas.

frew

Link to comment
Share on other sites

Note: I wrote this a bit earlier in the thread but forgot to send it so here it is, just a bit of info that might be of interest

regarding the _SendEx solution.

Also, I'm not sure why this is, but if I comment out the _SendEx in script_2.au3, then I can

change the _SendEx in script_3.au3 to Send (not _SendEx) and "Hello." prints fine, and I can go right into typing normally, ie no Alt key is being pressed down still.

So...what was that Send in script_2.au3 doing (the Send being now commented out in script_2.au3) that the Send in script_3.au3 is not doing? Hmmm...seems like the Send in script_3.au3 would cause a problem too, but it does not.

Just wanted to let you know this in case it could help figure out how to get things working here. Thanks.

Below is an example of what I refer to:

HotKeys_1.au3

HotKeySet("!{F1}", "_test")

While 1
    Sleep(1000)
WEnd

Func _test()
    ShellExecute(@AutoItExe, "script_1.au3", "C:\Program Files\AutoIt3")
EndFunc ;==>_test

script_1.au3 (Send/_SendEx commented out in this one)

#include <Misc.au3>

Func _SendEx($ss,$warn = "")
     Local $iT = TimerInit()
    
     While _IsPressed("10") Or _IsPressed("11") Or _IsPressed("12")
         if $warn <> "" and TimerDiff($iT) > 1000 Then
             MsgBox(262144, "Warning", $warn)
         EndIf
       sleep(50)
     WEnd
     Send($ss)
    
EndFunc;==>_SendEx


Sleep(1000)
ShellExecute(@AutoItExe, "script_2.au3", "C:\Program Files\AutoIt3")
Sleep(2000)
;_SendEx("{Enter}")

script_2.au3

#include <Misc.au3>

Func _SendEx($ss,$warn = "")
     Local $iT = TimerInit()
    
     While _IsPressed("10") Or _IsPressed("11") Or _IsPressed("12")
         if $warn <> "" and TimerDiff($iT) > 1000 Then
             MsgBox(262144, "Warning", $warn)
         EndIf
       sleep(50)
     WEnd
     Send($ss)
    
EndFunc;==>_SendEx


Sleep(1000)
Send("Hello.")

Thanks so much for any other ideas.

frew

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

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...