Jump to content

Ctrl - Shift key stuck


remin
 Share

Go to solution Solved by MHz,

Recommended Posts

This is my function to put round brackets "()" around a selected text:

HotKeySet("^+9", "Encl")  

While 1
    Sleep(10000)
WEnd


Func Encl()
 ClipPut("")
 Send( "^x" )
 Sleep(200)
 local $ClipEncl = ClipGet()

     Switch @HotKeyPressed
            Case "^+9"
              $ClipEncl = '(' & $ClipEncl & ')'
     EndSwitch

   ClipPut($ClipEncl )
 Send("^v")
EndFunc

The problem is that many times the ctrl or shift or ctrl-shift key is stuck after I invoke the above hotkey

and I have to push the ctrl, shift or both keys again to be able to use these as before.

Does anyone know what I did wrong in this function?

 
Edited by remin
Link to comment
Share on other sites

Is copy/paste and Clipget() the only way you can get the text you want into a variable before manipulation of the text?  What program are you working with?  There may be an easier way.

Edited by Blue_Drache

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

Link to comment
Share on other sites

Is copy/paste and Clipget() the only way you can get the text you want into a variable before manipulation of the text?  What program are you working with?  There may be an easier way.

 

I use this hotkey in various applications as my email client, text editors (vim, notepad etc) , word

Link to comment
Share on other sites

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

 

Thank you.

Do I have to change

send("my_value")

to 

_SendEx($ss, $warn = "")

?

 
And to clear lock down keys I have to put 
ControlSend("", "", "", "text", 0)

at the end of the function isn't it?

 
ps: There is nothing wrong in my script?
     Why does this script lock down keys
   and my other scripts don't?
 Has it to do also with the sleep value (10000)?
Edited by remin
Link to comment
Share on other sites

You're using a Control key as a modifier for your hotkey sequence, and in your Send sequence. The link I posted tells you how to avoid having that scenario cause the keys to "stick". Read it thoroughly as it explains it quite well.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

I don't understand it very well but I suppose I did it well in my previous reply.

There is no info where to place 
ControlSend("", "", "", "text", 0).

I still don't know what is the problem in my function and why my function stucks the ctrl and/or shift key and why other functions using the same commands don't.

Link to comment
Share on other sites

AutoIt has always suffered from what we call ShiftState. I am not aware of the ctrl key or alt key doing this though I do not see everything. Can you not avoid shift, you know the thing that supports locking shift?

Edit: or is it shiftlock, got me thinking now.

Edited by MHz
Link to comment
Share on other sites

I would like to avoid the shift key but my "(" character is invoked by using Ctrl-Shift-9 on my keyboard (US international keyb)

It is easier to remember to use the hotkey of the character I want to put around the selected text.

Edited by remin
Link to comment
Share on other sites

I would like to avoid the shift key but my "(" character is invoked by using Ctrl-Shift-9 on my keyboard (US international keyb)

It is easier to remember to use the hotkey of the character I want to put around the selected text.

 

Why not just ... not use the shift? 

Use Ctrl+9 ...

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

Link to comment
Share on other sites

Why not just ... not use the shift? 

Use Ctrl+9 ...

 

Because in my function in my question I deleted (for clarity reasons) other characters I use to put around selected text.

p.e. Quotes and Double Quotes. 

They are both under the same key on my keyboard.

Btw I noted that when I remove 

Sleep(200)

I have less problems with shift key stuck.

Why?

Blue_Drache.. do you know if I did well in my previous reply:

Link to comment
Share on other sites

Why just not avoid this happening by using:

#include-once
#include <WinAPIEx.au3>

;======================================================================================================================================================================================================

Func Press_COPY_Macross()
    _WinAPI_Keybd_Event(0x11, 0) ; CTRL Down
    _WinAPI_Keybd_Event(0x41, 0) ; a Down
    Sleep(8)
    _WinAPI_Keybd_Event(0x41, 2) ; a Up
    _WinAPI_Keybd_Event(0x11, 2) ; CTRL Up
    Sleep(8)
    _WinAPI_Keybd_Event(0x11, 0) ; CTRL Down
    _WinAPI_Keybd_Event(0x43, 0) ; c Down
    Sleep(8)
    _WinAPI_Keybd_Event(0x43, 2) ; c Up
    _WinAPI_Keybd_Event(0x11, 2) ; CTRL Up
EndFunc   ;==>Press_COPY_Macross

;======================================================================================================================================================================================================

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 get idea :sorcerer:  :)

Link to comment
Share on other sites

  • Solution

You change

Send("my_value")

to

_SendEx("my_value")

Here is a change to your code with the use of the linked code that BrewManNH posted to sleep until the Shift-Ctrl-Alt keys are released. I guess it shows that using the keyboard while using Send can activate the issue with key state. Best to deactivate the hotkey while the sleep happens else the queue can still be added to.

#include < Misc.au3 >
HotKeySet("^+9", "Encl")  

While 1
    Sleep(10000)
WEnd

Func Encl()
    ClipPut("")
    HotKeySet(@HotKeyPressed)
    While _IsPressed("10") Or _IsPressed("11") Or _IsPressed("12")
        Sleep(10)
    WEnd
    Send("^x")
    Sleep(200)
    local $ClipEncl = ClipGet()

    Switch @HotKeyPressed
        Case "^+9"
            $ClipEncl = '(' & $ClipEncl & ')'
    EndSwitch

    ClipPut($ClipEncl)
    Send("^v")
    HotKeySet(@HotKeyPressed, "Encl")
EndFunc

I have not been able to create the issue with testing this though if you like playing your keyboard like a piano then the _SendEx() is probably best to use to ensure all sends are covered.

:)

Link to comment
Share on other sites

  • 2 years later...

This is how i solved it dont know if this will help anyone. I was having to press the ctrl key manually after the script had ran. And for some reason separating the individual calls was causing it to freeze with the ctrl on. it seems like the delays were the problem from the get go...

sleep(1000) -----this is what i originally had and it would bring up the open file window but would put the RCTRL key in constant state of DOWN, and thought i could call a "manual" ctrl up after it opened the window. but that didnt work...
   send("{rCTRL down}{o down}")
   sleep(100)
    send("{o up}{rCTRL up}")
   sleep(1000)
   send("{rCTRL down}{rCTRL up}")

 

send("{RCTRL down}{o down}{o up}{RCTRL up}")      -------This worked for me----

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...