Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

CapsLock to Modify j,k,i,m to arrows, but support modifiers


  • Please log in to reply
17 replies to this topic
rathkopf
  • Members
  • 14 posts
  • Last active: Jun 23 2010 05:32 PM
  • Joined: 22 Oct 2008
I would like to use the CapsLock key as a modifer to j,k,i,m to send Left, Right, Up, Down. I also need this to support modifers like shift, control, and alt (shift for selecting text for example, or shift control to select an entire word.).

I am not having any luck.

I've done this:

CapsLock & k::Send {right}

but this doesn't support the modifiers.

Any suggestions to do this supporting the standard modifier keys.

(fyi: my ultimate goal is a version of touchcursor that will run on my laptop from and from my USB key.)

sinkfaze
  • Moderators
  • 6367 posts
  • Last active: Nov 30 2018 08:50 PM
  • Joined: 18 Mar 2008
Are you trying to modify those keys only when CapsLock is on? If so you probably need to use GetKeyState:

~k::
if GetKeyState("Capslock", "T") ; if CapsLock is on
  Send {RIGHT}
else
  Send k
return


rathkopf
  • Members
  • 14 posts
  • Last active: Jun 23 2010 05:32 PM
  • Joined: 22 Oct 2008
Actually, I want this to work when CapsLock is held down, not on.

Additionally, I tried your script, and when the caps lock is not "on" then two k's are sent. When CapsLock is ON, then a capital K is sent, but the insert point is to the left of the inserted character.

For my education, and to save me from searching through all the docs, can you explain what the tilda is for prior to the hot key character? (I know I've looked this up once, but I can't remember it. I'll probably find it again before an answer is posted. :? )

sinkfaze
  • Moderators
  • 6367 posts
  • Last active: Nov 30 2018 08:50 PM
  • Joined: 18 Mar 2008

Additionally, I tried your script, and when the caps lock is not "on" then two k's are sent. When CapsLock is ON, then a capital K is sent, but the insert point is to the left of the inserted character.


That's because of the tilde, it prevents the blocking of the key's native function when the hotkey is pressed. I meant to use $ which prevents the hotkey from triggering itself when it sends k. Since we're looking for the held down state and not the toggle state, this might work:

[color=red]$[/color]k::
if GetKeyState("Capslock", "[color=red]P[/color]") ; if CapsLock is being held down
  Send {RIGHT}
else
  Send k
return


rathkopf
  • Members
  • 14 posts
  • Last active: Jun 23 2010 05:32 PM
  • Joined: 22 Oct 2008
Thanks.

Better, but now CapsLock + Shift + k sends lower case k, rather than left arrow + shift which selects text.

Also, the CapsLock status is changing. I want CapsLock to stay off (or better yet, in it's last state).

Also, CapsLock+Shift+Ctrl+k should select the word to the left (like control-shift-left does normally). now it does nothing.

infogulch
  • Moderators
  • 717 posts
  • Last active: Jul 31 2014 08:27 PM
  • Joined: 27 Mar 2008
What about
#If GetKeyState("CapsLock", "P")

j::Left
k::Right
i::Up
m::Down

#If
?

Edit: Oops. :oops: I thought ahk supported the #If hotkey directive now. Nvm that won't work. :lol:

VxE
  • Moderators
  • 3622 posts
  • Last active: Dec 24 2015 02:21 AM
  • Joined: 07 Oct 2006

Edit: Oops. :oops: I thought ahk supported the #If hotkey directive now. Nvm that won't work. :lol:

Not quite, but this works
$~*Capslock::
Gui, 99:+ToolWindow
Gui, 99:Show, x-1 w1 +NoActivate, Capslock Is Down
keywait, Capslock
Gui, 99:Destroy
return

#IfWinExist, Capslock Is Down
	j::Left
	k::Right
	i::Up
	m::Down
#IfWinExist


rathkopf
  • Members
  • 14 posts
  • Last active: Jun 23 2010 05:32 PM
  • Joined: 22 Oct 2008
:D
Excellent. Thank you. When I get the rest of the script fleshed out I'll be sure to post.

DreymaR
  • Members
  • 89 posts
  • Last active: Jun 19 2013 08:03 AM
  • Joined: 24 May 2009
I use Farkas Máté's PortableKeyboardLayout for that, and more. Here's part of my pkl.ini file:

[extend]
; These keys are modified/transposed by holding down the 'extend key' (CapsLock by default):
;+------+------+------+------+------+------+------+------+------+------+------+------+------+
;|Esc + |F1 <> |F2 << |F3 >> |F4 <> |F5 <> |F6 << |F7 >> |F8 <> |F9 <> |F10<> |F11<> |F12<> |
;| Caps | Play | Prev | Next | Stop | Mute | Vol- | Vol+ | Media| BrHom| Mail | App1 | App2 |
;+======+======+======+======+======+======+======+======+======+======+======+======+======+
;|` ¤¤¤ |1     |2     |3     |4     |5     |6     |7     |8     |9     |0     |-     |=     |
;| Del  | F1   | F2   | F3   | F4   | F5   | F6   | F7   | F8   | F9   | F10  | F11  | F12  |
;+------+------+------+------+------+------+------+------+------+------+------+------+------+
;|Tab   |Q <<> |W +++ |F <>> |P *** |G *** |J ### |L ### |U ### |Y ### |; ¤¤¤ |[ ¤¤¤ |] ¤¤¤ |
;|      | BrBck| Win  | BrFwd| *WhUp| *Btn1| PgUp | Home | Up   | End  | Del  | Esc  | Ins  |
;+------+------+------+------+------+------+------+------+------+------+------+------+------+
;|Caps+ |A +++ |R +++ |S +++ |T *** |D *** |H ### |N ### |E ### |I ### |O ¤¤¤ |' ¤¤¤ |\ ><> |
;| ++++ | Alt  | Ctrl | Shift| *WhDn| *Up17| PgDn | Left | Down | Right| Back | Apps | BrFav|
;+------+------+------+------+------+------+------+------+------+------+------+------+------+
;|Z ¤¤¤ |X === |C === |V === |B *** |_ *** |K *** |M *** |, *** |. *** |/ *** |Spc ¤ |Entr¤ |
;| Esc  | Cut  | Copy | Paste| *Le17| *Dn17| *Ri17| *Btn3| *WhLe| *WhRi| *Btn2| Enter| Break|
;+------+------+------+------+------+------+------+------+------+------+------+-------------+
;Legend: # Movement; + Modifiers; = GUI edit; * Mouse; <> MultiMedia; ¤ Various commands.


; NOTES:
; - This map shows a 'comfort' Colemak with VK_102 in the middle (the '_' key). See below.
; - The actual remaps are by scan codes though, so the positions are layout independent!
; - Multiple extending modifiers would've been nice; this setup is a general/basic one.
; - For instance, extended virtual mousing, NumPad/maths, mirror layout, coder's toolbox...
; - If your layout doesn't define the key, 'extend' won't work with it!
;    * Workaround: Put, e.g., 'SC039 = SPACE	VirtualKey' in your layout .ini file.
;    * This will be necessary for Escape/Space/Return/Back and F1-F12 for full functionality.
; - The Tab key is currently a poor candidate for remapping because of problems with AltTab.
;    * It might be useable as another extensor/modifier though?
; - Unfortunately, the WARS (WASD) modifier block only works partially! A bug?
;    * The S=Shift and A=Alt work fairly well, but the R=CtRL is dodgy.
; - Are the "Wheel left/right" keys actual keys or AHK code?

; TIPS:
; - These mappings enable you to do many things without leaving the typing home position.
;    * Mappings are based on ease of reach vs. usefulness, and some left-hand-only use.
; - This could take some getting used to for the left pinky, but then it gets really cool!!!
; - The Caps key plus Esc turns the CapsLock state on and off now.
; - It's handy to control your browser back/forward with the left hand only while browsing.
; - Similarly, the wheel up/down keys are favorites.
; - Caps+Space for Enter is also nice; can be worked with left-hand-only as well.
;    * To press dialogue buttons for instance, use Tab to move and Space/Q to select/abort.
;    * A+Space (=Alt+Enter) when a file/disk is selected, brings up the object's Properties.
; - Use the \ (or *Btn2) for context menus; arrows, 'mousing' or shortcuts select items.
; - An Esc mapped to '[' (Telnet/Vim/etc compliant) is nice, but a left-hand one even better.
; - The left-hand Del key is also convenient; the right-hand one is best when editing.
; - Cut/Copy/Paste are Windows 'keypress' versions - should work mostly anywhere.
;    * I wished to have an Undo key on 'z', but that doesn't exist!?!
; - In theory, using WARS with the UNEI/LY/O' keys you can jump words, jump/select, etc.
;    * Not all these are currently working though, so you may have to use 'real' modifiers.
; - The number keys are mapped to function keys. They are reachable with the left hand!
;    * A4 closes apps; W3 GUI-searches; 1(Help)/2(Rename)/3(Find)/5(Refresh) are useful too.
; - The function keys are mapped to multimedia keys like the ones on multimedia keyboards.
;    * Browser_Stop/Refresh/Search are usually covered by hotkeys (e.g., Esc/F5/^F).
;    * Browser_Favorites usually needs a menu choice, so that's an inclusion candidate.
; - The App1/2 keys are defined in the registry, in a ShellExecute (REG_SZ) value under (?):
;    * HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\AppKey\17
;    * HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\AppKey\18
; - Wheel Up/Dn are nice for scrolling window bars; Wheel Left/Right for horizontal scroll.
; - The 'virtual mousing' is rudimentary; a 'last resort' when arrows/Tab aren't enough.
;    * A mousing resolution of 17 pixels roughly fits *most* context and similiar menus.
;    * A full mouse layout would have multi-resolution, diagonals, sticky Btn1 and Btn4/Btn5.
;    * The keyboard's auto-repeat makes virtual mousing odd/'laggy' when a key is held down.
;    * In particular, beware of holding down the *Btn key(s) for a 'rapid-click' effect.


; *** 'ESC'/'SPACE'
SC001 = CapsLock
SC039 = Enter

; *** 'F1'-'F12'
;The F key block holds multimedia keys, Logitech/Mac-style (F1-F4 are easiest to reach)
SC03b = Media_Play_Pause
SC03c = Media_Prev
SC03d = Media_Next
SC03e = Media_Stop
SC03f = Volume_Mute
SC040 = Volume_Down
SC041 = Volume_Up
SC042 = Launch_Media
SC043 = Browser_Home
SC044 = Launch_Mail
SC057 = Launch_App1
SC058 = Launch_App2

; *** Row 1 (numbers/symbols)
SC029 = Del
SC002 = F1
SC003 = F2
SC004 = F3
SC005 = F4
SC006 = F5
SC007 = F6
SC008 = F7
SC009 = F8
SC00a = F9
SC00b = F10
SC00c = F11
SC00d = F12
SC00e = Sleep

; *** Row 2 (upper letter row)
SC00f = Tab
SC010 = Browser_Back
SC011 = Win
SC012 = Browser_Forward
SC013 = WheelUp
SC014 = LButton
SC015 = PgUp
SC016 = Home
SC017 = Up
SC018 = End
SC019 = Del
SC01a = Esc
SC01b = Ins

; *** Row 3 (home row)
;SC03a = CapsLock 
SC01e = Alt
SC01f = Ctrl
SC020 = Shift
SC021 = WheelDown
SC022 = Click Rel 0,-17,0
SC023 = PgDn
SC024 = Left
SC025 = Down
SC026 = Right
SC027 = BackSpace
SC028 = AppsKey
SC02b = Browser_Favorites
SC01c = CtrlBreak

; *** Row 4 (lower letter row)
;SC02a = LShift
; ***** SEE THE [EXTRA] SECTION FOR OPTIONAL 'COMFORT' REGISTRY REMAPPING *****
; Non-registry-mapped 'comfort' layout - VK_102 in the lower left corner is used as 'Z'.
SC056 = Esc
SC02c = Cut
SC02d = Copy
SC02e = Paste
SC02f = Click Rel -17,0,0
SC030 = Click Rel 0,17,0
SC031 = Click Rel 17,0,0
SC032 = MButton
; ***** END OF 'COMFORT'/'NON-COMFORT' PART (PASTE BETWEEN THESE LINES) *******
SC033 = WheelLeft
SC034 = WheelRight
SC035 = RButton
;SC036 = RShift


[extra]
; This section is not read by the program, but contains snippets for other sections.

; Mappings for scan code mapped versus unmapped 'comfort' layout (ZXCVB+VK_102 keys)
; (These keys may already be mapped on a lower level than PKL, by registry)
; Copy the appropriate set into your pkl.ini -> [extend] section, row 4.

; Non-registry-mapped 'comfort' layout - VK_102 in the lower left corner is used as 'Z'.
SC056 = Esc
SC02c = Cut
SC02d = Copy
SC02e = Paste
SC02f = Click Rel -17,0,0
SC030 = Click Rel 0,17,0
SC031 = Click Rel 17,0,0
SC032 = MButton

; Non-registry-mapped 'non-comfort' layout - if you have no VK_102 key (or WANT pain?!).
SC02c = Esc
SC02d = Cut
SC02e = Copy
SC02f = Paste
SC030 = Click Rel 0,17,0
SC031 = Click Rel -17,0,0
SC032 = Click Rel 17,0,0
; Instead of a mouse 'cross', there's now up/down and left/right pairs.
; If you want the middle button, you may replace the left-hand Esc (but I wouldn't).

; Scancode/registry mapped 'comfort' layout - VK_102 now sits in the old 'B' position.
SC02c = Esc
SC02d = Cut
SC02e = Copy
SC02f = Paste
SC030 = Click Rel -17,0,0
SC056 = Click Rel 0,17,0
SC031 = Click Rel 17,0,0
SC032 = MButton

I greatly enjoy the power of all that, and it's right there on my USB stick at all times! For instance, to quit an app I'll press CapsLock and then 'A' and '4' for Alt-F4 to quit without leaving home position. Then, arrow keys like yours and the Space bar (for Enter) or 'Z' (for Escape) navigate menus. As you can see, there's a lot more there too.

Note that you'll need a layout which defines all the keys you're planning to 'extend'. The mappings may be a mere pass-through 'VirtualKey'.
Better burden you cannot carry than man-wisdom much -- Hávamál

rathkopf
  • Members
  • 14 posts
  • Last active: Jun 23 2010 05:32 PM
  • Joined: 22 Oct 2008
DreymaR

Thanks for pointing me to PKL.

Now, my next question is, can I map and extended key to press two other keys? I use J and L (actally Dvorak H and S) in TouchCoursor to move back and forward one word, i.e. ctrl-left and ctrl-right.

Can I do this with PortableKeyboardLayout?

thanks.

rathkopf
  • Members
  • 14 posts
  • Last active: Jun 23 2010 05:32 PM
  • Joined: 22 Oct 2008
I'd also like to Disable the CapsLock key for the CapsLock function, and rather map CapsLock to CapsLock+Tab.

Can this be done with PKL?

DreymaR
  • Members
  • 89 posts
  • Last active: Jun 19 2013 08:03 AM
  • Joined: 24 May 2009
In theory the two-stroke mapping should be easy enough, but somehow I didn't get it to work in PKL. What I do is press the Ctrl key with the CapsLock. For instance, to select a word backwards I'll press Caps-Ctrl-Shift-'N' (Colemak; that's QWERTY 'J' for the backwards and, uh, 'H' for you). I first tried to make it work with 'R' (QWERTY 'S'; Dvorak 'O') as Ctrl, but that didn't play well with the other kids on the letter block. I think the keyboard itself may be to blame and a non-aliased board might work. I'm using 'A' as Alt and 'S' as Shift with much better results.

I wouldn't use the Tab key because it's very useful as it is (unmapped) and sometimes mapping it will mess with integrated functionality such as Alt-Tabbing. I suggest using Caps+Esc or Caps+'`' instead. That's what I do.

To be sure the full 'extend' layout works and the CapsLock doesn't misbehave, I use the following snippet in the [layout] section of my layout .ini file:
; *** Using 'CapsLock' as 'extend_key' works best if it is mapped but otherwise disabled
CapsLock = OEM_CAPITAL	0	--	--	--	--	--	; CapsLock
; *** To make a key work with the 'extend_key' modifier, it needs to be virtual-mapped as below.
; *** When VirtualKey-mapping the BACKSPACE/ENTER keys, use their enumerations BACK/RETURN.
; *** Remapping the TAB key is problematic: Alt-Tab becomes 'sticky', needing Esc to get out.
SC001 = ESCAPE	VirtualKey
SC00e = BACK	VirtualKey
;SC00f = TAB	VirtualKey
SC01c = RETURN	VirtualKey
SC039 = SPACE	VirtualKey
SC03b = F1	VirtualKey
SC03c = F2	VirtualKey
SC03d = F3	VirtualKey
SC03e = F4	VirtualKey
SC03f = F5	VirtualKey
SC040 = F6	VirtualKey
SC041 = F7	VirtualKey
SC042 = F8	VirtualKey
SC043 = F9	VirtualKey
SC044 = F10	VirtualKey
SC057 = F11	VirtualKey
SC058 = F12	VirtualKey

Better burden you cannot carry than man-wisdom much -- Hávamál

rathkopf
  • Members
  • 14 posts
  • Last active: Jun 23 2010 05:32 PM
  • Joined: 22 Oct 2008
Thanks again. Probably right about the Tab. In my home-grown remapping I had used the escape, so capslock+escape actually toggled the capslock. I'll stick with that.

Bummer on the two-stroke mapping. I didn't get it to work either. I tried ^Left and ^Right, but that didn't do it.

Maybe someone else will shed light on this.

Thanks for your snippit. I'll have to include that.

infogulch
  • Moderators
  • 717 posts
  • Last active: Jul 31 2014 08:27 PM
  • Joined: 27 Mar 2008
You can use [VxE]'s method of remapping with two strokes. (make the first key create a hidden gui window). Just name each gui differently and use different gui numbers, and there ya go.

DreymaR
  • Members
  • 89 posts
  • Last active: Jun 19 2013 08:03 AM
  • Joined: 24 May 2009
Remapping two strokes in AHK is no problem for sure. It's a bit more tricky with Portable Keyboard Layout it seems. Of course, if it matters to you there's always the AHK source code for PKL - so you could do anything you wanted if you want to invest the effort.
Better burden you cannot carry than man-wisdom much -- Hávamál