Jump to content
Sign in to follow this  
remin

Ctrl - Shift key stuck

Recommended Posts

remin

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

Share this post


Link to post
Share on other sites
Blue_Drache

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

Share this post


Link to post
Share on other sites
remin

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

Share this post


Link to post
Share on other sites
BrewManNH
  • Like 1

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

Share this post


Link to post
Share on other sites
remin

 

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

Share this post


Link to post
Share on other sites
BrewManNH

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

Share this post


Link to post
Share on other sites
remin

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.

Share this post


Link to post
Share on other sites
MHz

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
  • Like 1

Share this post


Link to post
Share on other sites
remin

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

Share this post


Link to post
Share on other sites
Blue_Drache

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

  • Like 1

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

Share this post


Link to post
Share on other sites
remin

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:

Share this post


Link to post
Share on other sites
Iczer

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:  :)

Share this post


Link to post
Share on other sites
remin

I changed 

send("my_value")

to 

_SendEx($ss, $warn = "")

 

in all my functions.

It seems to work fine now.

Is it correct what I've done???

Share this post


Link to post
Share on other sites
MHz

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.

:)

  • Like 1

Share this post


Link to post
Share on other sites
Hondadriver1234

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

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  

  • Similar Content

    • spuuunit
      By spuuunit
      This is what I'm trying to do: In Firefox, if you hold down CTRL + C for about 200ms, then press CTRL + T. This is my code:
      While WinActive(" - Mozilla Firefox") If _IsPressed("A2", $hDLL) And _IsPressed("43", $hDLL) Then $timer = TimerInit() While _IsPressed("A2", $hDLL) And _IsPressed("43", $hDLL) Sleep(10) $diff = TimerDiff($timer) If $diff > 200 Then Send("^{T}") While _IsPressed("A2", $hDLL) And _IsPressed("43", $hDLL) Sleep(10) WEnd EndIf WEnd EndIf WEnd The problem is that the CTRL key gets stuck down after Send("^{T}"). I found this, but what I understand that happens when I release, and that is not what I want. The "General unstuck method" did nothing.
    • ruslanas402
      By ruslanas402
      Greeting, so I've been trying to come up with solution, but no luck. Despite I tried to automate upload function, I released that it freezes after "Choose File to Upload" window appears..
       
      #include <IE.au3> ;#include <_Dbug.au3> Global $oIE = _IECreate("http://tinypic.com/", 1) Global $upload2 = _IEGetObjById($oIE, "the_file") _IEAction($upload2, "click") ;Sleep(1000) $hWnd = WinGetHandle("Choose File to Upload") MsgBox(0, "", $hWnd) Have anybody faced this situation?
      btw: srry for the advertise Besides it's no matter which site I'm trying to do this it's all the same.
    • UEZ
      By UEZ
      I want that the Listview acts as CTRL key was pressed by default to avoid any deletion when the listview was clicked.
      Here an example code:
      #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <GUIListView.au3> $hGUI = GUICreate("ListView Test", 400, 550) $iLV = GUICtrlCreateListView("", 0, 10, 400, 480, $LVS_SHOWSELALWAYS, BitOR($LVS_EX_FLATSB, $LVS_EX_CHECKBOXES, $LVS_EX_FULLROWSELECT, $LVS_EX_DOUBLEBUFFER)) _GUICtrlListView_AddColumn($iLV, "Date", 100, 1) _GUICtrlListView_AddColumn($iLV, "Size (bytes)", 100, 1) _GUICtrlListView_AddColumn($iLV, "File Name", 100, 1) For $i = 0 to 150 _GUICtrlListView_AddItem($iLV, "Row " & $i) _GUICtrlListView_AddSubItem($iLV, $i, $i * 2, 1) _GUICtrlListView_AddSubItem($iLV, $i, $i * 4, 2) Next $cButton = GUICtrlCreateButton("Reset", 10, 510, 80, 30) GUISetState() _GUICtrlListView_SetItemChecked($iLV, 0) _GUICtrlListView_SetItemSelected($iLV, 0) _GUICtrlListView_SetItemChecked($iLV, 1) _GUICtrlListView_SetItemSelected($iLV, 1) _GUICtrlListView_SetItemChecked($iLV, 2) _GUICtrlListView_SetItemSelected($iLV, 2) ControlFocus($hGUI, "", $iLV) ; Create array to hold selection state Global $aSelected[_GUICtrlListView_GetItemCount($iLV)] GUIRegisterMsg($WM_NOTIFY, "_WM_NOTIFY") While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit Case $cButton ; Clear all selections _GUICtrlListView_SetItemSelected($iLV, -1, False) ; Clear selected array Global $aSelected[_GUICtrlListView_GetItemCount($iLV)] EndSwitch WEnd Func _WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam) #forceref $hWnd, $iMsg, $wParam ; Struct = $tagNMHDR and "int Item;int SubItem" from $tagNMLISTVIEW Local $tStruct = DllStructCreate("hwnd;uint_ptr;int_ptr;int;int", $lParam) If @error Then Return Local $tNMHDR = DllStructCreate($tagNMHDR, $lParam) Local $hWndFrom = HWnd($tNMHDR.hWndFrom) Local $iIDFrom = $tNMHDR.IDFrom Local $iCode = $tNMHDR.Code Local Static $iCount = 0 Local $tInfo = DllStructCreate($tagNMLISTVIEW, $lParam) Switch $iCode Case $LVN_ITEMCHANGED If BitAND($tInfo.Changed, $LVIF_STATE) = $LVIF_STATE Then Switch $tInfo.NewState Case 8192 ;item checked _GUICtrlListView_SetItemSelected($iLV, $tInfo.Item, True) Case 4096 ;item unchecked _GUICtrlListView_SetItemSelected($iLV, $tInfo.Item, False) EndSwitch EndIf Case $NM_CLICK $tInfo = DllStructCreate($tagNMITEMACTIVATE, $lParam) ;~ _DebugPrint("$NM_CLICK" & @CRLF & "--> hWndFrom:" & @TAB & $hWndFrom & @CRLF & _ ;~ "-->IDFrom:" & @TAB & $iIDFrom & @CRLF & _ ;~ "-->Code:" & @TAB & $iCode & @CRLF & _ ;~ "-->Index:" & @TAB & $tInfo.Index & @CRLF & _ ;~ "-->SubItem:" & @TAB & $tInfo.SubItem & @CRLF & _ ;~ "-->NewState:" & @TAB & $tInfo.NewState & @CRLF & _ ;~ "-->OldState:" & @TAB & $tInfo.OldState & @CRLF & _ ;~ "-->Changed:" & @TAB & $tInfo.Changed & @CRLF & _ ;~ "-->ActionX:" & @TAB & $tInfo.ActionX & @CRLF & _ ;~ "-->ActionY:" & @TAB & $tInfo.ActionY & @CRLF & _ ;~ "-->lParam:" & @TAB & $tInfo.lParam & @CRLF & _ ;~ "-->KeyFlags:" & @TAB & $tInfo.KeyFlags) _GUICtrlListView_SetItemChecked($iLV, $tInfo.Index, _GUICtrlListView_GetItemState($iLV, $tInfo.Index, $LVIS_SELECTED)) EndSwitch Return $__LISTVIEWCONSTANT_GUI_RUNDEFMSG EndFunc Func _DebugPrint($s_Text , $sLine = @ScriptLineNumber) ConsoleWrite( _ "!===========================================================" & @CRLF & _ "+======================================================" & @CRLF & _ "-->Line(" & StringFormat("%04d", $sLine) & "):" & @TAB & $s_Text & @CRLF & _ "+======================================================" & @CRLF) EndFunc ;==>_DebugPrint Just cklick the listview and you will see that the selection is deleted. Repeat it and hold the CTRL key pressed.
      Any ideas?
      I don't want to read the listview and check whether the checkbox is checked and mark the row appropriately! It's lagging...
       
      Thanks,
      UEZ
    • Servant
      By Servant
      For example my GUICtrlCreateEdit() contains:
      Line 1 Line 2 Line 3 When I IniWrite() the content of it, the value will be look like this:
      [SectionName] Key=Line 1 Line 2 Line 3 But when I IniRead() that key like this:
      GUICtrlCreateEdit(IniRead(@ScriptDir & "/data.ini", "SectionName", "Key", ""), 1, 1, 200, 100) The value of the GUI edit field is only "Line 1"..
      How can I INI write and read a text with line breaks in a GUICtrlCreateEdit() ?
×