Sign in to follow this  
Followers 0
Just1f

Keyboard key unreleased

10 posts in this topic

#1 ·  Posted (edited)

I have a tool which waits events 98% of its time in here:

While 1
    ShowToolTip()
    Sleep(500)
WEnd

ShowToolTip() just refresh a small info box in top corner of the screen.

I made it set a hotkey on CTRL+i:

HotKeySet("^i", "ToggleInvisibility")

The function ToggleInvisibility() uses Send() to write a command, nothing really relevant here.

When the function ends it returns in the loop, but the Ctrl key is still understood by Windows as pressed. I get back on Windows, I close the script and the CTRL key is still considered as pressed, even when the script has exited !

AutoIt seems to do something bad to windows. Anyway just physically typing once again on CTRL will unlock the issue, But I cant get it done wiith AutoScript, I tried to modify my main loop so it looks like :

While 1
    ShowToolTip()
    If _IsPressed("11") Then 
        Send("{CTRLDOWN}")
    EndIf
    Sleep(500)
WEnd

I tried combinations of "^", "{CTRLUP}", "{CTRLDOWN}" nothing worked....

Help I am stuck !

Edited by Just1f

Share this post


Link to post
Share on other sites



I have a tool which waits events 98% of its time in here:

While 1
    ShowToolTip()
    Sleep(500)
WEnd

ShowToolTip() just refresh a small info box in top corner of the screen.

I made it set a hotkey on CTRL+i:

HotKeySet("^i", "ToggleInvisibility")

The function ToggleInvisibility() uses Send() to write a command, nothing really relevant here.

When the function ends it returns in the loop, but the Ctrl key is still understood by Windows as pressed. I get back on Windows, I close the script and the CTRL key is still considered as pressed, even when the script has exited !

AutoIt seems to do something bad to windows. Anyway just physically typing once again on CTRL will unlock the issue, But I cant get it done wiith AutoScript, I tried to modify my main loop so it looks like :

While 1
    ShowToolTip()
    If _IsPressed("11") Then 
        Send("{CTRLDOWN}")
    EndIf
    Sleep(500)
WEnd

I tried combinations of "^", "{CTRLUP}", "{CTRLDOWN}" nothing worked....

Help I am stuck !

The problem would appear to be that you are pressing the CTRL key but never releasing it.

Have you tried this

While 1
    ShowToolTip()
    If _IsPressed("11") Then
        NosConsoleWrite("Magic")
        Send("{CTRLDOWN}{CTRLUP}")
    EndIf
    Sleep(500)
WEnd

"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the universe trying to build bigger and better idiots. So far, the universe is winning."- Rick Cook

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

The problem would appear to be that you are pressing the CTRL key but never releasing it.

Have you tried this

While 1
    ShowToolTip()
    If _IsPressed("11") Then
        NosConsoleWrite("Magic")
        Send("{CTRLDOWN}{CTRLUP}")
    EndIf
    Sleep(500)
WEnd
Yes I did : _IsPressed() is still detecting the CTRL key and the ctrl key is not detected released.

This bug seems to happen when I release CTRL key very quickly just after the secondary shortcut key

Edited by Just1f

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

I have an idea about the problem :

When I type CTRL, first the windows application catches it (keypress), then I type 'i' and AutoIt takes control as it is a shortcut. Then the scripts executes and I release the CTRL key during this time but nothing reads that key... So this key release is lost in a "black hole"...

Edit: it seems the black hole was a BlockInput...

How can I manage BlockInput to not block CTRL ?

Second edit : I removed all the BlockInput, it happens less, but still happens. I am desperate :-(

Edited by Just1f

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

I am really stuck, no one has an idea ? The problem is still the following :

Sometimes, on a script that does NOT uses BlockInput(), the CTRL key is still considered as pressed by Windows even when the script is finished. Happens only when user uses a CTRL+KEY shortcut (HotkeySet("^i", foobar()) for example, foobar() doing some keys input).

Edited by Just1f

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

I am really stuck, no one has an idea ? The problem is still the following :

Sometimes, on a script that does NOT uses BlockInput(), the CTRL key is still considered as pressed by Windows even when the script is finished. Happens only when user uses a CTRL+KEY shortcut (HotkeySet("^i", foobar()) for example, foobar() doing some keys input).

I have often had the same problem with the Ctrl key staying 'operated' but I have not been able to reliably reproduce it. Pressing the Ctrl key after the script has ended always clears it.

In one script I added a delay waiting for the Ctrl key to be released before sending "^",

While _IsPressed(11)
wend
Send("^...

but that script doesn't always show the problem without the delay so I can't be sure it fixes it.

Can you provide a script where this problem always occurs? If you can, and if someone else can verify it, then you could make a bug report.

Here is an idea to try. Because I don't know how AutoIt deals with sending Ctrl plus some key I can't say if this idea is sensible. But supposing the problem is that when AutoIt sends "^h" say it does it by sending a simulated Ctrl down, then h then Ctrl up, and maybe something goes wrong with the Ctrl Up. So instead of "^h" try something like this and see if it makes any difference

Send(Chrs(Asc("h") - Asc("a")));send the single character for Ctrl h

Or maybe you could try

Send("{CTRLDOWN}")
sleep(20);in case it matters
Send("h")
sleep(20)
Send("{CTRLUP}")

It is also worth trying increasing the down delay in case windows is missing something.

Opt("SendKeyDownDelay",20);increase the Send key down delay from default of 5
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.

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

The following script shows that AutoIt is not able to detect CTRL key release when it is running Send().

1. Copy the script

2. Execute it

3. Open notepad

4. Type CTRL+h

5. Release CTRL when it is typing

6. Type any alphabetical key to see that your ctrl key is still pressed (type ctrl once again to go back to normal)

7. Maybe you will have to try it twice before catching the issue

Const $SCREEN_WAIT = 150

Func WriteMessage($message)
    Send($message)
EndFunc

Func WriteStuff()
    WriteMessage("`test1 test1")
    Sleep(1000)
EndFunc

Func ExitTool()
    Exit
EndFunc

Func ConfigureHotKeys() 
    HotKeySet("^h", "WriteStuff")
    HotKeySet("{F11}", "ExitTool")
EndFunc

Func Main()
    Opt("GUIOnEventMode", 1)
    Opt("SendKeyDelay", 100)
    Opt("MouseClickDelay", 0)
    AutoItSetOption("WinTitleMatchMode", 2)
    AutoItSetOption("PixelCoordMode", 2)
    ConfigureHotKeys()
    While 1
        Sleep(1000)
    WEnd
EndFunc

Main()
Edited by Just1f

Share this post


Link to post
Share on other sites

The following script shows that AutoIt is not able to detect CTRL key release when it is running Send().

1. Copy the script

2. Execute it

3. Open notepad

4. Type CTRL+h

5. Release CTRL when it is typing

6. Type any alphabetical key to see that your ctrl key is still pressed (type ctrl once again to go back to normal)

7. Maybe you will have to try it twice before catching the issue

Const $SCREEN_WAIT = 150

Func WriteMessage($message)
    Send($message)
EndFunc

Func WriteStuff()
    WriteMessage("`test1 test1")
    Sleep(1000)
EndFunc

Func ExitTool()
    Exit
EndFunc

Func ConfigureHotKeys() 
    HotKeySet("^h", "WriteStuff")
    HotKeySet("{F11}", "ExitTool")
EndFunc

Func Main()
    Opt("GUIOnEventMode", 1)
    Opt("SendKeyDelay", 100)
    Opt("MouseClickDelay", 0)
    AutoItSetOption("WinTitleMatchMode", 2)
    AutoItSetOption("PixelCoordMode", 2)
    ConfigureHotKeys()
    While 1
        Sleep(1000)
    WEnd
EndFunc

Main()
That's good. If I release the Ctrl key while send is sending a string then it always results in the Ctrl being down.

I think the reason is that when Send starts it has to check if the Ctrl key is pressed, and other keys. So it can send the correct characters it has to first send CTRLUP. When it's finished it sends CTRLDOWN if it was originally down, but what it should do is check if it's still pressed.

This mod to your example works everytime I've tried it wheras before the bug showed every time, but there is a delay while it waits for the Ctrl key to be released.

#include <GUIConstants.au3>
#include <misc.au3>

Const $SCREEN_WAIT = 150

Func WriteMessage($message)
    While _IsPressed(11)
        WEnd
    Send($message)
EndFunc

Func WriteStuff()
    WriteMessage("`test1 test1")
    Sleep(1000)
EndFunc

Func ExitTool()
    Exit
EndFunc

Func ConfigureHotKeys() 
    HotKeySet("^h", "WriteStuff")
    HotKeySet("{F11}", "ExitTool")
EndFunc

Func Main()
    Opt("GUIOnEventMode", 1)
    Opt("SendKeyDelay", 100)
    Opt("MouseClickDelay", 0)
    AutoItSetOption("WinTitleMatchMode", 2)
    AutoItSetOption("PixelCoordMode", 2)
    ConfigureHotKeys()
    While 1
        Sleep(1000)
    WEnd
EndFunc

Main()

I think you should submit this as an error report, I think this gives enough information for it to be fixed.


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.

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

Yup, there is a bug.

FINALLY I found a rather simple solution based on Martin's hints :

While 1
        If _IsPressed("11") Then
            Sleep(100)
        Else
            Send($message)
            Return
        EndIf
    WEnd

(Hint: design a simple CtrlKeyCheck() function based on that)

Edited by Just1f

Share this post


Link to post
Share on other sites

#10 ·  Posted (edited)

Yup, there is a bug.

FINALLY I found a rather simple solution based on Martin's hints :

While 1
        If _IsPressed("11") Then
            Sleep(100)
        Else
            Send($message)
            Return
        EndIf
    WEnd

(Hint: design a simple CtrlKeyCheck() function based on that)

@Justif - Are you going to report this as a bug?

EDIT: I see it has been reported.

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.

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