CapsLock (trigger/hot) key "stuck"

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
downstairs
Posts: 42
Joined: 17 Aug 2017, 11:42

Re: CapsLock (trigger/hot) key "stuck"

Post by downstairs » 13 Oct 2020, 12:56

mikeyww wrote:
13 Oct 2020, 12:45
Why not use hotstrings? You can have as many as you want. Easier to remember, too. You just type in a few letters of regular text, and AHK will convert them into whatever you want. I have hundreds of them. You could even use the same letters as your current hotkeys, like typing "su" will do whatever S & U are supposed to do. Easy. I also have a AHK launcher script-- you are welcome to it-- that loads my LNK file names and lets me run any of them from a simple ListView GUI. I can even just type one or two keys to jump to the files starting with those letters.

Example of hotstring that executes a program (uses my path for Photoshop):

Code: Select all

:X:rp::Run, C:\Program Files\Adobe\Adobe Photoshop 2020\Photoshop.exe
Of course, you have to be typing into a window to make this work.

Another example:

Code: Select all

:O:qe::expedia{ENTER}
Type qe into your favorite place.

Hey... this sounds very interesting. I'd love to see your launcher script and/or anything that will help me grasp this new way of doing things.

I appreciate your help with this!
User avatar
mikeyww
Posts: 27372
Joined: 09 Sep 2014, 18:38

Re: CapsLock (trigger/hot) key "stuck"

Post by mikeyww » 13 Oct 2020, 14:02

I'm planning to provide this launcher script in the scripts forum, but here it is for you. It is very simple to use. Copy any LNK shortcut files of interest into a single folder. In the script, just change LNKdirectories so that it names that folder. You can have more than one such folder in that array. Run the script. That's it. It will build a GUI from those files. WIN / launches the GUI; you can change the shortcut. Select a file to run from the GUI. You can type the first few letters to jump to it. I tried lots of launchers-- Launchy, Keypirinha, and a few others-- all quite good-- but this one is as good as any of them for those who don't need the other features that some of them have. You can rename your shortcut files to anything you want, to make it easier for you to find and run them from this GUI. If you make a change to the shortcut files, update the GUI simply by reloading the script. I keep this running at all times and use it at least a few times every hour.

Code: Select all

/* mwLaunch --------------------------------------------
By Michael Weiner, Indianapolis, Indiana, U.S.A. on 13 October 2020
This AutoHotkey script displays a ListView that enables launching of programs using their LNK shortcut files.
This script may be run alone, or included in another script if "GoSub, LaunchStart" is issued at the start.
Modify LNKdirectories to refer to directories that contain LNK shortcut files to be listed in the GUI.
If needed, modify the hotkey to launch the GUI. The current hotkey is WIN-/ (WIN key combined with "/").
https://www.autohotkey.com/boards/viewtopic.php?f=76&t=81937
--------------------------------------------------------
*/
LaunchStart:
; --- Directories with LNK files to be listed in GUI -------------
LNKdirectories := ["E:\data\quicklaunch"
 , "E:\data\utils\lnk"]
; ----------------------------------------------------------------
Global LaunchList
getLaunches(LNKdirectories)
Return

; --- Hotkey to launch the GUI -----------------------------------
#/::Gui, Launch:Show

; --- No need to change anything below this line -----------------

LaunchButtonOK:
GuiControlGet, fcontrol, FocusV
If (fcontrol != "LaunchList")
 Return
LV_GetText(app, LV_GetNext("F"), 2) ; Get the path from the focused line in the ListView
Gosub, LaunchGuiEscape ; Hide the GUI
Run, %app%
Return

LaunchGuiEscape:
Gui, Launch:Hide
Return

getLaunches(launchDirs) {
 For index, launchDir in launchDirs { ; Loop through the launch directories
  Loop, Files, % launchDir "\*.*", R ; Find each file in the directory; include subdirectories
  {
   SplitPath, A_LoopFileName,,,, fnBare ; Find the file name without extension
   If A_LoopFileExt not in ini ; Skip INI files
    list .= "`n" (A_LoopFileExt = "lnk" ? fnBare : A_LoopFileName) "`t" A_LoopFileFullPath ; Build the list
  }
 }
 list2 := SubStr(list, 2), list := "" ; Delete the first line feed
 Sort, list2
 Loop, parse, list2, `n, `r ; Eliminate duplicates
 {
  fn := RegExReplace(A_LoopField, "^(.+)\t.+$", "$1")
  If (fn != oldFN) ; This item is not a duplicate
   list .= "`n" A_LoopField, oldFN := fn
 } 
 list := SubStr(list, 2), part := {}
 Gui, Launch:New,, Launch list ; Build the GUI
 Gui, Launch:Font, s10
 Gui, Launch:Add, ListView, BackgroundF9DDC7 r22 w700 vLaunchList Count1200 Grid -Multi, Name|Path
 GuiControl, -Redraw, LaunchList
 Loop, parse, list, `n, `r
 {
  Loop, parse, A_LoopField, `t
   part[A_Index] := A_LoopField
  LV_Add("", part.1, part.2) ; Add each item to the listview: file name and full path
 }
 GuiControl, +Redraw, LaunchList
 LV_ModifyCol() ; Auto-size each column to fit its contents.
 Gui, Launch:Add, Button, w0 h0 hidden Default, OK ; User can select an entry and then press ENTER to execute
}
downstairs
Posts: 42
Joined: 17 Aug 2017, 11:42

Re: CapsLock (trigger/hot) key "stuck"

Post by downstairs » 13 Oct 2020, 14:11

mikeyww wrote:
13 Oct 2020, 14:02
I'm planning to provide this launcher script in the scripts forum, but here it is for you. It is very simple to use. Copy any LNK shortcut files of interest into a single folder. In the script, just change LNKdirectories so that it names that folder. You can have more than one such folder in that array. Run the script. That's it. It will build a GUI from those files. WIN / launches the GUI; you can change the shortcut. Select a file to run from the GUI. You can type the first few letters to jump to it. I tried lots of launchers-- Launchy, Keypirinha, and a few others-- all quite good-- but this one is as good as any of them for those who don't need the other features that some of them have. You can rename your shortcut files to anything you want, to make it easier for you to find and run them from this GUI. If you make a change to the shortcut files, update the GUI simply by reloading the script. I keep this running at all times and use it at least a few times every hour.

Code: Select all

/* mwLaunch --------------------------------------------
By Michael Weiner, Indianapolis, Indiana, U.S.A. on 13 October 2020
This AutoHotkey script displays a ListView that enables launching of programs using their LNK shortcut files.
This script may be run alone, or included in another script if "GoSub, LaunchStart" is issued at the start.
Modify LNKdirectories to refer to directories that contain LNK shortcut files to be listed in the GUI.
If needed, modify the hotkey to launch the GUI. The current hotkey is WIN-/ (WIN key combined with "/").
https://www.autohotkey.com/boards/viewtopic.php?f=76&t=81937
--------------------------------------------------------
*/
LaunchStart:
; --- Directories with LNK files to be listed in GUI -------------
LNKdirectories := ["E:\data\quicklaunch"
 , "E:\data\utils\lnk"]
; ----------------------------------------------------------------
Global LaunchList
getLaunches(LNKdirectories)
Return

; --- Hotkey to launch the GUI -----------------------------------
#/::Gui, Launch:Show

; --- No need to change anything below this line -----------------

LaunchButtonOK:
GuiControlGet, fcontrol, FocusV
If (fcontrol != "LaunchList")
 Return
LV_GetText(app, LV_GetNext("F"), 2) ; Get the path from the focused line in the ListView
Gosub, LaunchGuiEscape ; Hide the GUI
Run, %app%
Return

LaunchGuiEscape:
Gui, Launch:Hide
Return

getLaunches(launchDirs) {
 For index, launchDir in launchDirs { ; Loop through the launch directories
  Loop, Files, % launchDir "\*.*", R ; Find each file in the directory; include subdirectories
  {
   SplitPath, A_LoopFileName,,,, fnBare ; Find the file name without extension
   If A_LoopFileExt not in ini ; Skip INI files
    list .= "`n" (A_LoopFileExt = "lnk" ? fnBare : A_LoopFileName) "`t" A_LoopFileFullPath ; Build the list
  }
 }
 list2 := SubStr(list, 2), list := "" ; Delete the first line feed
 Sort, list2
 Loop, parse, list2, `n, `r ; Eliminate duplicates
 {
  fn := RegExReplace(A_LoopField, "^(.+)\t.+$", "$1")
  If (fn != oldFN) ; This item is not a duplicate
   list .= "`n" A_LoopField, oldFN := fn
 } 
 list := SubStr(list, 2), part := {}
 Gui, Launch:New,, Launch list ; Build the GUI
 Gui, Launch:Font, s10
 Gui, Launch:Add, ListView, BackgroundF9DDC7 r22 w700 vLaunchList Count1200 Grid -Multi, Name|Path
 GuiControl, -Redraw, LaunchList
 Loop, parse, list, `n, `r
 {
  Loop, parse, A_LoopField, `t
   part[A_Index] := A_LoopField
  LV_Add("", part.1, part.2) ; Add each item to the listview: file name and full path
 }
 GuiControl, +Redraw, LaunchList
 LV_ModifyCol() ; Auto-size each column to fit its contents.
 Gui, Launch:Add, Button, w0 h0 hidden Default, OK ; User can select an entry and then press ENTER to execute
}

Ok, awesome... let me check out these ideas, along with the easier "hotstrings" idea...

I'm still trying to figure out the best flow of what I need to do with hotstrings. I don't fully understand the syntax other than the very simple example:

Code: Select all

::btw::
MsgBox You typed "btw".
return
I want "s" and "u" to populate with my signature for my company named "Unique NOLA Tours". But... I can see myself typing the letters "su" and the end string (space?) in normal type. So I can't have it replace when I type the word, say "Tiramisu"... if that makes sense...
User avatar
mikeyww
Posts: 27372
Joined: 09 Sep 2014, 18:38

Re: CapsLock (trigger/hot) key "stuck"

Post by mikeyww » 13 Oct 2020, 14:55

No problem there. Hotstrings work when they are bound by defined delimiters such as a space. You can type your normal words that contain "su"! Try it in a script.

Code: Select all

::su::Unique NOLA Tours
Read Hotstrings.
downstairs
Posts: 42
Joined: 17 Aug 2017, 11:42

Re: CapsLock (trigger/hot) key "stuck"

Post by downstairs » 13 Oct 2020, 14:57

mikeyww wrote:
13 Oct 2020, 14:55
No problem there. Hotstrings work when they are bound by defined delimiters such as a space. You can type your normal words that contain "su"! Try it in a script.

Code: Select all

::su::Unique NOLA Tours
Read Hostrings.
Quick question, what are the "X" and "O" in these examples you had in a previous comment?
:X:rp::Run, C:\Program Files\Adobe\Adobe Photoshop 2020\Photoshop.exe
:O:qe::expedia{ENTER}
User avatar
mikeyww
Posts: 27372
Joined: 09 Sep 2014, 18:38

Re: CapsLock (trigger/hot) key "stuck"

Post by mikeyww » 13 Oct 2020, 15:05

It's in the chapter. You'll learn everything if you look at it!

X: Instead of sending the text on the line, it runs (eXecutes) the command on the line.

O: Omits the trailing delimiter. This is handy in many cases, depending on what you need to type after the text. Useful in your example because you have ENTER immediately after the text, so you probably do not want the trailing space (for example) to appear after that.

Re the hotstring syntax: if you put text after the "::" on the same line, that text is sent, and the hotstring routine ends. The alternative is to put commands on subsequent lines, followed by Return.
downstairs
Posts: 42
Joined: 17 Aug 2017, 11:42

Re: CapsLock (trigger/hot) key "stuck"

Post by downstairs » 13 Oct 2020, 15:56

mikeyww wrote:
13 Oct 2020, 15:05
It's in the chapter. You'll learn everything if you look at it!

X: Instead of sending the text on the line, it runs (eXecutes) the command on the line.

O: Omits the trailing delimiter. This is handy in many cases, depending on what you need to type after the text. Useful in your example because you have ENTER immediately after the text, so you probably do not want the trailing space (for example) to appear after that.

Re the hotstring syntax: if you put text after the "::" on the same line, that text is sent, and the hotstring routine ends. The alternative is to put commands on subsequent lines, followed by Return.
Indeed, I am understanding the hotstrings page... but I'm not seeing where I can, rather than type "su" as a hotstring (which is causing all sorts of problems when I DON'T want to add the signature... where I can, say, bind it to hitting "S" and keeping it down, then hitting "U"

Essentially

Code: Select all

S & U::
However, that seems to disable "S" completely?

I guess I'm at a loss as to how to make this quick and constant... but not invasive and prone to misfiring when I don't want it to.
User avatar
mikeyww
Posts: 27372
Joined: 09 Sep 2014, 18:38

Re: CapsLock (trigger/hot) key "stuck"

Post by mikeyww » 13 Oct 2020, 16:59

Code: Select all

~S & U::Send {BS}Unique NOLA Tours
downstairs
Posts: 42
Joined: 17 Aug 2017, 11:42

Re: CapsLock (trigger/hot) key "stuck"

Post by downstairs » 14 Oct 2020, 08:11

mikeyww wrote:
13 Oct 2020, 16:59

Code: Select all

~S & U::Send {BS}Unique NOLA Tours
Thank you so much MikeyWW!

This is a great start to maybe doing things a different way.

I'd still love to figure out my original issue with both why the keys get stuck, and also why a simple hack can't seem to unstick them.

But you've been very helpful all around.
User avatar
mikeyww
Posts: 27372
Joined: 09 Sep 2014, 18:38

Re: CapsLock (trigger/hot) key "stuck"

Post by mikeyww » 14 Oct 2020, 08:54

Your original script disables so many keys that it would be easy to misinterpret what is happening. I'm glad that you are moving in a direction that seems to be helping.

Remember, with an "su" hotstring, it doesn't execute unless you type "su" by itself (separated by delimiters such as a space).
downstairs
Posts: 42
Joined: 17 Aug 2017, 11:42

Re: CapsLock (trigger/hot) key "stuck"

Post by downstairs » 14 Oct 2020, 15:38

mikeyww wrote:
14 Oct 2020, 08:54
Your original script disables so many keys that it would be easy to misinterpret what is happening. I'm glad that you are moving in a direction that seems to be helping.

Remember, with an "su" hotstring, it doesn't execute unless you type "su" by itself (separated by delimiters such as a space).
I am curious... where in my original AHK script can I fire something after any CapsLock + (whatever) is done firing?

I've put the following, and it does not fire. Note that L & 6:: should be the final string of keys in the long list.

Code: Select all

L & 6::
SendInput, {tab 4}{up 6}{enter}
Sleep, 500
SendInput, {ctrl down}s{ctrl up}
Return

MsgBox, "TEST"
User avatar
mikeyww
Posts: 27372
Joined: 09 Sep 2014, 18:38

Re: CapsLock (trigger/hot) key "stuck"

Post by mikeyww » 14 Oct 2020, 15:50

Easy answer: any code that should execute every time the script is run goes at the top of the script, in a section called auto-execute (read all about it at the link). That must precede hotkeys, hotstrings, and other labeled subroutines.

The documentation is actually a great source of information. It contains clear explanations and many examples. If you spend an hour with it, it might save you the next three hours!
downstairs
Posts: 42
Joined: 17 Aug 2017, 11:42

Re: CapsLock (trigger/hot) key "stuck"

Post by downstairs » 07 Nov 2020, 15:20

Hey all... so I've been looking more into this.

Apparently keyboards are built with 6-key-rollover or N-key-rollover, which allows at least 6 multiple keys to be detected at the same time (if not more).

If I want to stick with my three-key hotkeys, do you think getting a keyboard that has specs to handle this many keys at once would help solve this?

I ask because completely redoing my workflow to only have two-key AHK hotkeys is going to be a massive overhaul.

And apparently "key rollover" is a thing.
User avatar
mikeyww
Posts: 27372
Joined: 09 Sep 2014, 18:38

Re: CapsLock (trigger/hot) key "stuck"

Post by mikeyww » 07 Nov 2020, 15:38

I doubt it!
Dragoods
Posts: 7
Joined: 17 Jul 2020, 05:16

Re: CapsLock (trigger/hot) key "stuck"

Post by Dragoods » 19 Nov 2022, 18:36

Same reason, same problem.

Code: Select all

CapsLock & a:: Backspace
CapsLock & s:: Enter
CapsLock & d:: Delete
I'm using simpleast things like this and even face the same problem. Occasionally, I delete things pressing 'a' just after using "CapsLock & s" to append a line. In fact, this happens often...

Reeeeeeeeeeeeeeeeeeeeally ANOYING!
Dragoods
Posts: 7
Joined: 17 Jul 2020, 05:16

Re: CapsLock (trigger/hot) key "stuck"

Post by Dragoods » 21 Nov 2022, 19:19

Ok, fine, I sort of figure out a script to manage the "Capslock-stuck problem" when errors occur.

Code: Select all

$CapsLock::
  ToolTip, CapsLock+, A_CaretX, A_CaretY, 1
  if (A_PriorHotkey == "$CapsLock" AND A_TimeSincePriorHotkey < 200){
    KeyWait, CapsLock, T 0.1
    if (ErrorLevel = 1)
      Send, ^y
    else
      Send, ^z
  }
  KeyWait, CapsLock
  ToolTip
return

#If GetKeyState("CapsLock", "P")
	;TODO things with Capslock pressing down;
#If
It does 3 things:
1. Have a Tooltip to remind whether "Capslock" is pressing down (or if it is released as hoped);
2. Undo error inputs by double-tap Capslock, this will clear the "Capslock-stuck" state as well;
3. Over-undoing? Just double-tap and hold Capslock for a while to Re-do things.

------------------------------------------------------------------

Another problem is that, A_CaretX & A_CaretY is set to return the "text insertion point" position. However, it just gets the cursor's position on my computer because the caret position cannot be determined (leave variables in blank), anybody knows why?
Post Reply

Return to “Ask for Help (v1)”