## Add 3 more layers to your keyboard Using these 3 Modifiers - Easy to Program Too!

Helpful script writing tricks and HowTo's
survargs
Posts: 8
Joined: 23 Jul 2016, 16:21

### Add 3 more layers to your keyboard Using these 3 Modifiers - Easy to Program Too!

The following is a simple script that starts with the holding down of either Caps, Num, or Scroll-lock and the pressing of another key or mouse press to do basically, anything you can think of. It is also very easy to program as something like k::Down is quite simply if you hold down the modifier and press the letter "k", send the down arrow key.

As for the CapsLock modifier, this script is able to recognize if you are using it as a modifier or are just toggling it.
In short, this caps lock script written by XXO back on the old forums which I then have expanded on and use everyday.
Here is his exact post back in 2014:

Code: Select all

CapsLock::
KeyWait, CapsLock
If (A_PriorKey="CapsLock")
SetCapsLockState, % GetKeyState("CapsLock","T") ? "Off" : "On"
Return
#If, GetKeyState("CapsLock", "P") ;Your CapsLock hotkeys go below

w::Up
a::Left
s::Down
d::Right
q::Send % (A_PriorHotKey = A_ThisHotkey && A_TimeSincePriorHotkey < 200) ? "{Blind}^{Home}" : "{Blind}{PGUP}"
e::Send % (A_PriorHotKey = A_ThisHotkey && A_TimeSincePriorHotkey < 200) ? "{Blind}^{End}" : "{Blind}{PGDN}"

The coolest part about this is how easy it is to program these modifier + hotkey combinations
On the left hand side is your letter or combination of caps lock & key presses, and on the right hand side is what you want AHK to do.

I took this a step further and using SharpKeys, remapped my registry to make my RAlt into NumLock and my RWindows Key into ScrollLock and I will explain why.
The easy to follow tutorial I used was the how-to-geek article titled "Map Any Key to Any Key on Windows 10, 8, 7, or Vista"
You really don't use these anyway and I usually have my numlock on all the time. If you have extra buttons on your mouse, you can also add your scroll lock or num lock there too.

Your average keyboard has 104 keys, and with these 3 new modifiers, you now have an additional 3 layers giving your keyboard 4 layers of possibilities.
The NumLock modifier will not un-toggle your numpad after using it as a modifier(had to force the NumLockStateto ON for NumLock and the opposite for ScrollLock.

Anyway, just to give you an idea of how I use it personally, here is my code.
You'll see it is a lot of trial and error and there is not right or wrong way to use this.
The following hotkeys I use a lot:

;::Send {BS}
Space::Send {Return}
i::Up
j::Left
k::Down
l::Right

and with that, you'll practically never have to hit the actual backspace, enter, or arrow keys during normal typing.
note: you can also use "keyhistory" to find out SC codes and use those with these modifiers too.
If you have a mouse with a wheel, you can use wheel left/right , up/down or xbutton1/2 (ie special buttons on some mouses), Lbutton(left click), Rbutton(right), and Mbutton(middle) do also execute certain things too, you'll see I execute programs with it.

Anyway here it is as I use it currently, enjoy!

Code: Select all

#NoEnv
SendMode Input
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.
;keyhistory
;#InstallMouseHook
#installkeybdhook
SetNumLockState,On
SetNumLockState,AlwaysOn

SetScrollLockState,Off
SetScrollLockState,AlwaysOff
return
;

CapsLock::
KeyWait, CapsLock
If (A_PriorKey="CapsLock")
SetCapsLockState, % GetKeyState("CapsLock","T") ? "Off" : "On"
Return

#If, GetKeyState("CapsLock", "P") ;Your CapsLock hotkeys go below

;i::+Tab
i::Up
j::Left
;k::Tab
k::Down
l::Right ;u::Send {Home}
u::-  ;o::Send {End}
;u::Send {End}
o::Run C:\A Steel Trap\Duo\best ahk\done\move_from_photos_to_end_of_title.ahk
;o::Send {End} ;p::Send {PgUp}
p::Run C:\A Steel Trap\Duo\best ahk\done\item_specifics.ahk  ;p::Send {Home}
[::Send {End}
]::Send {PgDn}
=::Send {PgUp}
;::Send {BS}
Space::Send {Return}
0::Send {PgUp}
1::6
2::7
3::8
4::9
5::
SC029::-

WheelLeft::^PgUp
WheelRight::^PgDn
;XButton2::Home
;XButton1::End

sc045::Send {down 9}
Wheeldown::Down
Wheelup::Up
!m::Run C:\A Steel Trap\Duo\best ahk\search_master_list_box.ahk
^F7::Run C:\A Steel Trap \Duo\best ahk\close firefox tabs to the right.ahk
^PgUp::Run C:/A Steel Trap/Duo/best ahk/done/photo_gallery.ahk
^PgDn::Run C:/A Steel Trap/Duo/best ahk/done/photo_gallery_open_double_including_previous_photo.ahk
Numlock::Run C:\A Steel Trap\Duo\best ahk\6bitStart.ahk

LButton::Run C:\A Steel Trap\Duo\best ahk\activatesixbit.ahk
;RButton::Run C:\A Steel Trap\Duo\best ahk\ahk to do\clickdragphotos.ahk
RButton::Run C:\A Steel Trap\Duo\best ahk\done\organize_photo_order_click.ahk
MButton::Run C:\A Steel Trap\Duo\best ahk\done\organize_photo_order_shoes-dbltagmove_click.ahk
Enter::^v
PgUp::Volume_Up
PgDn::Volume_Down
Right::Media_Next
Left::Media_Prev
Down::Media_Play_Pause
q::y
;w::u
w::Run C:\A Steel Trap\Duo\best ahk\done\google.ahk
;e::i
e::!d
r::o
t::p
y::send t-strap 

;a::h
;s::j
;d::k
;f::l
a::Run C:\A Steel Trap\Duo\best ahk\done\firefox.ahk
s::f4
d::^w
f::^t

g::send t-shirt
h::Run C:\A Steel Trap\Duo\best ahk\clickwind_pending_pics.ahk

z::b
x::n
c::m
v::send v-neck  ;v::Run C:\A Steel Trap\Duo\best ahk\done\save_and_exit.ahk ;b::send pullover  ;n::Run C:\A Steel Trap\Duo\best ahk\done\centermouse&click.ahk
b::send t-strap 
;n::Up
;n::+Tab
n::Send .5
;m::Down
;m::Send {-}
m::+Tab
;Send {-}
;m::send {#} ;Tab::Send {Tab 5}
;Tab::Send {Tab 3} ;
Tab::Run C:\A Steel Trap\Duo\best ahk\timenowdate.ahk
End::Run C:\A Steel Trap\Duo\best ahk\done\saveclose2.ahk
;^F11::Run C:\A Steel Trap\Duo\best ahk\ahk to do\clickwind_delete_photos.ahk
;,::Send .5  ;,::Send {!}
,::Send /P
.::Send .5
;.::Run C:\A Steel Trap\Duo\best ahk\done\new_item.ahk
/::Run C:\A Steel Trap\Duo\best ahk\done\saveclose2.ahk
;Backspace::Run C:\A Steel Trap\Duo\best ahk\ahk to do\clickdragphotos.ahk
Backspace::Run C:\A Steel Trap\Duo\best ahk\done\photo_gallery_close_all_photos.ahk
;Backspace::Run C:\A Steel Trap\Duo\best ahk\done\organize_photo_order_click.ahk
;Run C:\A Steel Trap\Duo\best ahk\music\copy.ahk
;Left::+Tab
;Delete::Run C:\A Steel Trap\Duo\best ahk\music\copy.ahk
^c::Run C:\A Steel Trap\Duo\best ahk\clickwind_pending_pics.ahk

;
ScrollLock::
KeyWait, ScrollLock
If (A_PriorKey="ScrollLock")
SetScrollLockState, % GetKeyState("ScrollLock","T") ? "Off" : "On"
Return

#If, GetKeyState("ScrollLock", "P") ;Your ScrollLock hotkeys go below

;i::+Tab
i::s
a::Run C:\A Steel Trap\Duo\best ahk\done\new_item_clear_photos.ahk
s::Run C:\A Steel Trap\Duo\best ahk\done\organize_photo_order.ahk
;d::Run C:\A Steel Trap\Duo\best ahk\done\organize_photo_order_shoes-dbltagmove.ahk
Tab::f4
Numpad9::Run C:\A Steel Trap\Duo\best ahk\click_win_sold_items_search_when_shipping.ahk
t::Send personal email
;w::^w
w::^t
f::Run C:\A Steel Trap\Duo\best ahk\done\firefox.ahk
g::Run C:\A Steel Trap\Duo\best ahk\done\google.ahk

Up::Send {Up 5}
;

NumLock::
KeyWait, NumLock

#If, GetKeyState("NumLock", "P")

Numpad1::Run C:\A Steel Trap\Duo\best ahk\done\saveclose2.ahk
;Numpad5::Run C:\A Steel Trap\Duo\best ahk\click_win_sold_items_search_when_shipping.ahk
Numpad8::Send phone number
;NumpadSub::SC028  ;this is for the single quotation character
NumpadDiv::Run C:\A Steel Trap\Duo\best ahk\done\saveclose2.ahk
NumpadMult::Run C:\A Steel Trap\Duo\best ahk\done\brackets.ahk

e::+Tab
d::Tab
a::Run C:\A Steel Trap\Duo\best ahk\6bitStart.ahk
s::Run C:\A Steel Trap\Duo\best ahk\done\item_specifics.ahk
q::Run C:\A Steel Trap\Duo\best ahk\done\saveclose2.ahk
;f::Run C:\A Steel Trap\Duo\best ahk\done\add_single_listing.ahk
f::send c108
d::Send Does not Apply
r::Run C:\A Steel Trap\Duo\best ahk\done\move_mouse_to_shipping.ahk
w::Run C:\A Steel Trap\Duo\best ahk\done\change_price.ahk
v::Run C:\A Steel Trap\Duo\best ahk\done\new_item.ahk
Tab::Send {Tab 5}
4::Send 14-14.5 - S mens 
5::Send 15-15.5 - M mens
6::Send 16-16.5 - L mens 
7::Send 17-17.5 - XL mens
8::Send 18-18.5 - 2XL mens 
Space::Send {Space 7}
t::Send otheremail
i::+Tab
k::Tab
;::Send {BS}
j::Send {Tab 7}

Return

;

GollyJer
Posts: 59
Joined: 19 Sep 2015, 19:33
GitHub: GollyJer

### Re: Add 3 more layers to your keyboard Using these 3 Modifiers - Easy to Program Too!

Go here if interested.

This is really cool! Thanks for posting. It works great for CapsLock.

I was trying to do the same thing for Ctrl...

Code: Select all

#If GetKeyState("Ctrl", "P")
;Control key modifiers here.
#If
...but it isn't working. Any ideas? Is it because Ctrl is an official AHK modifier?[/i]
Last edited by GollyJer on 27 Nov 2016, 23:16, edited 1 time in total.
enne

### Re: Add 3 more layers to your keyboard Using these 3 Modifiers - Easy to Program Too!

Hi,
your code is great, using it all the time.

The only problem is that when i keep capslock pressed to use the arrow function and then release it, it activates the "real" function of capslock.
I would like to use it in normal function when pressed once and like modifier key with capslock function deactivated if long pressed.

Any solution to this?

Thank you very much
Acecool
Posts: 37
Joined: 10 Jan 2016, 18:25
GitHub: Acecool
Contact:

### Re: Add 3 more layers to your keyboard Using these 3 Modifiers - Easy to Program Too!

enne: I've noticed that with my script too... I have to end up reloading it when that happens.. I added the lines to turn off capslock each time it is pressed because of this...

Here's mine ( Capslock to use the Windows 10 Virtual Desktop Task Viewer which I did because I never use capslock, and because I can't run Logitech SetPoint because of how poorly it works with games and it also changes the feel of the mouse so enabling and disabling it each time I want to play a game isn't good... SetPoint kills your mouse buttons, basically instead of allowing you to hold them down it treats a press-and-hold as press-and-release and the release is ignored, among other things ):

Code: Select all

;;
;; CapsLock OnRelease Hook - Capslock now works like Win + Tab..
;;
CapsLock up::
SetCapsLockState, off
Send { Blind }{ Lwin up }
return

;;
;; CapsLock OnPress Hook - Capslock now works like Win + Tab..
;;
CapsLock::
SetCapsLockState, off
Send { Blind }{ CapsLock up }{ LWin down }{ Tab }
return
As for why this happens.. I'm not sure.. It could be that the script you're running is busy with other things and the hotkey is skipped because of this ( When I finish my ahk framework I am going to test this )..

Edit: The other reason I was posting this example is because the Topic Creator is using KeyWait ( which DOES prevent anything else from running ) instead of CapsLock:: and CapsLock UP:: ... KeyWait is deprecated or frowned upon because it is a blocking call...
-Josh 'Acecool' Moser
I teach various programming languages, game programming, etc... I am also taking on programming jobs as my health allows.
Nextron
Posts: 1373
Joined: 01 Oct 2013, 08:23
Location: Netherlands OS: Win10 AHK: Unicode x32

### Re: Add 3 more layers to your keyboard Using these 3 Modifiers - Easy to Program Too!

survargs wrote:In short, this caps lock script written by XXO back on the old forums which I then have expanded on and use everyday.
I thought the fragment looked familiar, but that's because I posted as XX0 on the old forum. Thanks for the shout-out.
I took this a step further and using SharpKeys, remapped my registry to make my RAlt into NumLock and my RWindows Key into ScrollLock
Resourceful, but a bit over-complex. Since AHK allows for distinction of the left/right modifier keys already using the < and > prefixes with modifier prefixes ^, !, + and #. So:

Code: Select all

^space::MsgBox Either control + space triggers this unless a hotkey is defined specific to the left of right modifier.
<^space::MsgBox Only left control + space triggers this.
>^space::MsgBox Only right control + space triggers this.
GollyJer wrote: I was trying to do the same thing for Ctrl...

Code: Select all

#If GetKeyState("Ctrl", "P")
;Control key modifiers here.
#If
...but it isn't working. Any ideas? Is it because Ctrl is an official AHK modifier?
Indeed, see above. Hotkeys without ^ or * will not trigger if control is logically down (so it must be logically up), but your other condition is that Control is physically down. So your hotkey can be triggered, but it's just an uncommon scenario, and not as you intended.
enne wrote:The only problem is that when i keep capslock pressed to use the arrow function and then release it, it activates the "real" function of capslock.
I would like to use it in normal function when pressed once and like modifier key with capslock function deactivated if long pressed.
Acecool wrote:enne: I've noticed that with my script too... I have to end up reloading it when that happens.. I added the lines to turn off capslock each time it is pressed because of this...
Curious, that is not the intended behavior. By hooking CapsLock, the native function should be suppressed, preventing toggling its state. I would suspect a driver or other hook with higher precedence or even multiple keyboards from interfering. Specifically, the code depends on the key repeat of CapsLock to cease after a subsequent key is pressed.
The other reason I was posting this example is because the Topic Creator is using KeyWait ( which DOES prevent anything else from running ) instead of CapsLock:: and CapsLock UP:: ... KeyWait is deprecated or frowned upon because it is a blocking call...
This is probably in reference to Why you should avoid while(GetKeyState("a", "P")) to detect release of key. While threading does need to be taken into consideration when deciding between KeyWait or the ... up:: hotkey; in this case the code mimics the (now suppressed) native function of CapsLock if no keys were pressed (i.e. CapsLock was not used as a hotkey).
• If no other keys were pressed, no user input has interrupted the code execution, so toggling is swift.
• If a hotkey did interrupt the thread, it will will finish delayed, but it was not intended not do anything anyway.
• If anything else interrupted the thread (timer, message), toggling CapsLock will be delayed. If it is noticeable, the interrupt will probably cause delays elsewhere too.
Regardless, it shouldn't be the cause of CapsLock toggling when used as a hotkey.
Acecool
Posts: 37
Joined: 10 Jan 2016, 18:25
GitHub: Acecool
Contact:

### Re: Add 3 more layers to your keyboard Using these 3 Modifiers - Easy to Program Too!

I seem to have figured it out...

Code: Select all

;;
;; CapsLock OnRelease Hook - Capslock now works like Win + Tab..
;;
CapsLock up::
Send { Blind }{ Lwin up }
SetCapsLockState, off
return

;;
;; CapsLock OnPress Hook - Capslock now works like Win + Tab..
;;
CapsLock::
Send { Blind }{ CapsLock up }{ LWin down }{ Tab }
SetCapsLockState, off
return
vs

Code: Select all

;;
;; CapsLock OnRelease Hook - Capslock now works like Win + Tab..
;;
CapsLock up::
Send {Blind}{Lwin up}
SetCapsLockState, off
return

;;
;; CapsLock OnPress Hook - Capslock now works like Win + Tab..
;;
CapsLock::
Send {Blind}{CapsLock up}{LWin down}{Tab}
SetCapsLockState, off
return

The second one works, the first one makes LAlt get stuck down until I manually press it... Strange or? I prefer writing airy-code to make it more readable but those spaces really seem to screw things up.....

I've been running into a lot of annoying issues with my AHK code and it seems to be linked to those spaces... ie keys getting stuck...
-Josh 'Acecool' Moser
I teach various programming languages, game programming, etc... I am also taking on programming jobs as my health allows.
guest3456
Posts: 2930
Joined: 09 Oct 2013, 10:31

### Re: Add 3 more layers to your keyboard Using these 3 Modifiers - Easy to Program Too!

jonnyhotkeys
Posts: 8
Joined: 18 Jan 2016, 13:26

### Re: Add 3 more layers to your keyboard Using these 3 Modifiers - Easy to Program Too!

awesome stuff.

I have no numpad / (dedicated) scroll lock on my laptop, just a caps lock (with an LED)

I'd like to use this as a secondary state - if CAPS LOCK is on ...

Code: Select all

CapsLock up::
Send { Blind }{ Lwin up }
SetCapsLockState, off
return

does this or (any of!) the above do this, or are they 'while caps-lock is held down' ?
is there a way of doing OSD (state) feedback (for debugging) ?

total(ly grateful) noob
Nextron
Posts: 1373
Joined: 01 Oct 2013, 08:23
Location: Netherlands OS: Win10 AHK: Unicode x32

### Re: Add 3 more layers to your keyboard Using these 3 Modifiers - Easy to Program Too!

The first code fragment from the first post does exactly that.
iseahound
Posts: 479
Joined: 13 Aug 2016, 21:04
GitHub: iseahound

### Re: Add 3 more layers to your keyboard Using these 3 Modifiers - Easy to Program Too!

Hey there nextron, just wanted to show my appreciation for having used your script for plenty of years.

This is a refinement of your original efforts, mainly this makes Capslock into a TRUE MODIFYING KEY by preventing the activation of Capslock when used in conjunction with other modifiers, as well as making the activation of CapslockState into a quick double-tap.

Code: Select all

CapsLock::
KeyWait, CapsLock                      ; wait for Capslock to be released
KeyWait, CapsLock, D T0.2              ; and pressed again within 0.2 seconds
if ErrorLevel
return
else if (A_PriorKey = "CapsLock")
SetCapsLockState, % GetKeyState("CapsLock","T") ? "Off" : "On"
return
*CapsLock:: return                        ; This forces capslock into a modifying key.

#If, GetKeyState("CapsLock", "P") ;Your CapsLock hotkeys go below
a::         Highlight.case.lower()
s::         Highlight.case.upper()
d::         Highlight.case.sentence()
f::         Highlight.case.title()
#If

class Highlight {

Copy() {
AutoTrim Off
c := ClipboardAll
Clipboard := ""             ; Must start off blank for detection to work.
Send, ^c
ClipWait 0.5
if ErrorLevel
return
t := Clipboard
Clipboard := c
VarSetCapacity(c, 0)
return t
}

Paste(t) {
c := ClipboardAll
Clipboard := t
Send, ^v
Sleep 50                    ; Don't change clipboard while it is pasted! (Sleep > 0)
Clipboard := c
VarSetCapacity(c, 0)        ; Free memory
AutoTrim On
}

class Case {

Lower(data := "") {
text := (data == "") ? Highlight.copy() : data
StringLower, lower, text
return (data == "") ? Highlight.paste(lower) : lower
}

Upper(data := "") {
text := (data == "") ? Highlight.copy() : data
StringUpper, upper, text
return (data == "") ? Highlight.paste(upper) : upper
}

Title(data := "") {
text := (data == "") ? Highlight.copy() : data
StringUpper, title, text, T
return (data == "") ? Highlight.paste(title) : title
}

Sentence(data := "") {
text := (data == "") ? Highlight.copy() : data
X := "I,LOL"
S := ""
T := RegExReplace(text, "[\.\!\?]\s+|\R+|\t+", "\$0þ")
Loop Parse, T, þ
{
StringLower L, A_LoopField
I := Chr(Asc(A_LoopField))
StringUpper I, I
S .= I SubStr(L,2)
}
Loop Parse, X, ,
S := RegExReplace(S, "i)\b" A_LoopField "\b", A_LoopField)
return (data == "") ? Highlight.paste(S) : S
}
}
}
Hopefully my code is self-explanatory. If it's not then: Open a word processor. Paste some random text. Highlight a portion of the random text. Press CapsLock + S. Your text should now be capitalized.

EDIT: I wonder if I should post this somewhere else, this utility looks so damn useful. Also I have many more text transformations including to bold, italic, serif, sans-serif, changing code indentations from tabs to 4 spaces, or 3, or 2; bulleting and numbering lists; hashes; as well as sending highlighted text directly to google or the command prompt. Anyone interested?
Nextron
Posts: 1373
Joined: 01 Oct 2013, 08:23
Location: Netherlands OS: Win10 AHK: Unicode x32

### Re: Add 3 more layers to your keyboard Using these 3 Modifiers - Easy to Program Too!

iseahound wrote:Hey there nextron, just wanted to show my appreciation for having used your script for plenty of years.

This is a refinement of your original efforts, mainly this makes Capslock into a TRUE MODIFYING KEY by preventing the activation of Capslock when used in conjunction with other modifiers, as well as making the activation of CapslockState into a quick double-tap.
Much appreciated!

Coincidentally I considered changing the hold activation to double tapping only a few days ago. Then I came to the conclusion that I actually never use CapsLock to type caps and rather want it as a custom toggle button for my F## keys and WASD, since twelve function buttons are way to few and CapsLock+WASD proves my favorite keyboard model is unfortunately 2-key role-over. Not sure how I'm going to proceed with that yet, perhaps SetCapsLockState,Off and use KeyBoardLED() for the visual feedback. Did something similar to make NumLock trinary.
I wonder if I should post this somewhere else, this utility looks so damn useful. Also I have many more text transformations including (...)
I'd definitely consider this useful enough to share and distinct enough from CapsLock hotkeying to warrant a separate thread.
burque505
Posts: 1100
Joined: 22 Jan 2017, 19:37

### Re: Add 3 more layers to your keyboard Using these 3 Modifiers - Easy to Program Too!

Thanks, iseahound.
EDIT: I wonder if I should post this somewhere else, this utility looks so damn useful. Also I have many more text transformations including to bold, italic, serif, sans-serif, changing code indentations from tabs to 4 spaces, or 3, or 2; bulleting and numbering lists; hashes; as well as sending highlighted text directly to google or the command prompt. Anyone interested?
I'm very interested in anything to do with bulleting and numbering lists, especially multilevel/outlining. I look forward to more.
survargs
Posts: 8
Joined: 23 Jul 2016, 16:21

### Re: Add 3 more layers to your keyboard Using these 3 Modifiers - Easy to Program Too!

Appreciate the feedback and glad to see this has helped others.
The topic was originally planned around using modifiers(capslock) that I played around with and added numlock and scroll lock.

Well, there is something that I have always wanted the answer to for the past 4 years and I have finally found it thanks to a post from Frankie that I stumbled upon the other day!!!
There is a way to add multiple layers without modifiers that you can build in to your existing code.

The post is from:
Frankie
//autohotkey.com/board/topic/61037-toggle-between-2-sets-of-hotkeyshotstrings/?p=384707

Code: Select all

#If Status == 1
::btw::by the way
::lol::laughing out loud
;YOU CAN ADD YOUR EXISTING CODE HERE IN ITS ENTIRETY
#If Status == 2
::btw::be the winner  ;I personally use f8 here
::lol::lots of laughs   ;I personally use SC029 or the   key under Esc

#If
F2::Status := 1
F3::Status := 2
Note: when you now launch your newly edited script, you will need to press the hotkey specified to enter your desired status (in the example above, you would press f2 at the start).

Lastly, I have only played around with this for less than 48 hours but it is incredibly powerful and can enable you in the use of even more "layers" with a single keyboard press.
I ran into some issues getting this to work but I found this to be a good place to put the status==1 in my code:

Code: Select all

#NoEnv
SendMode Input
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.
;keyhistory
;#InstallMouseHook

#If Status == 1

#installkeybdhook
SetNumLockState,On
SetNumLockState,AlwaysOn

SetScrollLockState,Off
SetScrollLockState,AlwaysOff
return
;then the rest of my script is below

Errors I have found using this method:
switching between these two modes works almost perfectly with one exception...
When you go from Status 1 to your new Status 2...for some reason the modifier commands are still able to be triggered and I don't know why.
Personally I am just careful when in Status 2 not to accidentally trigger the modifier scripts in Status1

Bonus:

For my own purposes, I wanted a way to work in a script to automatically return to Status 1 and I found that the following worked without any issues:
So I enter Status 2 with a keypress(for me it is SC029 or or the  key under Esc).
Then in this Status...I have a script that if triggered, simply contains the following:

SendInput {Blind}{F8}

This instantly reverts me back to Status 1 without having to press f8 again(especially useful if you want to keep your hand on the mouse)

P.S.
Some people have said that they have been having some trouble while using the capslock modifier to execute strings or code...notably Acecool and enne.
I have been using this code since the post without alteration on a windows 7 machine and now a windows 10 machine without any issues.
Be sure to do the following:

hold down capslock
press the key to execute the code or script you want to launch
release capslock

Note: if you don't press a key or execute anything using this capslock modifier then capslock will be triggered normally and you will see the LED show up on your keyboard.
Nextron
Posts: 1373
Joined: 01 Oct 2013, 08:23
Location: Netherlands OS: Win10 AHK: Unicode x32

### Re: Add 3 more layers to your keyboard Using these 3 Modifiers - Easy to Program Too!

survargs wrote:When you go from Status 1 to your new Status 2...for some reason the modifier commands are still able to be triggered and I don't know why.
Any #If is conditional to the hotkeys below it and overwrites any conditions set by a previous #If (they don't stack unless you explicitly write it to). So if you want your (CapsLock) i hotkey to only be active when status=1, you'll want to update the Getkeystate line, e.g:

Code: Select all

#If, GetKeyState("CapsLock", "P") && Status == 1 ;Your CapsLock hotkeys go below
i::Up
#If Status == 1
::btw::by the way
::lol::laughing out loud
;YOU CAN ADD YOUR EXISTING CODE HERE IN ITS ENTIRETY
#If Status == 2
::btw::be the winner
::lol::lots of laughs
survargs
Posts: 8
Joined: 23 Jul 2016, 16:21

### Re: Add 3 more layers to your keyboard Using these 3 Modifiers - Easy to Program Too!

Nextron wrote:
survargs wrote:When you go from Status 1 to your new Status 2...for some reason the modifier commands are still able to be triggered and I don't know why.
Any #If is conditional to the hotkeys below it and overwrites any conditions set by a previous #If (they don't stack unless you explicitly write it to). So if you want your (CapsLock) i hotkey to only be active when status=1, you'll want to update the Getkeystate line, e.g:

Code: Select all

#If, GetKeyState("CapsLock", "P") && Status == 1 ;Your CapsLock hotkeys go below
i::Up
#If Status == 1
::btw::by the way
::lol::laughing out loud
;YOU CAN ADD YOUR EXISTING CODE HERE IN ITS ENTIRETY
#If Status == 2
::btw::be the winner
::lol::lots of laughs

How logical. Never knew that, thanks!
Had no idea I was overriding my own code this way but it makes perfect sense now why I was getting those "bugs" before.

Made the adjustments and this is now working flawlessly!

One final question if you don't mind me asking Nextron.
Something like SendInput {Blind}{F8} does trigger one of my #If conditionals
but
SendInput {Blind}{SC029} yields  and does not [/u] #If trigger my other conditional?

For some reason I could never get this to work when attempting to have a single key press launch a script to trigger my other #If conditional trigger (in my case, this was the  key.

Thanks!
Nextron
Posts: 1373
Joined: 01 Oct 2013, 08:23
Location: Netherlands OS: Win10 AHK: Unicode x32

### Re: Add 3 more layers to your keyboard Using these 3 Modifiers - Easy to Program Too!

survargs wrote:One final question if you don't mind me asking Nextron.
Something like SendInput {Blind}{F8} does trigger one of my #If conditionals
but
SendInput {Blind}{SC029} yields ` and does not [/u] #If trigger my other conditional?
In order to explain it I have to get technical and nitpicky: SendInput {Blind}{F8} doesn't trigger the #If check either. If triggers the hotkey you've set up to set Status := 1. Hotkeys can be set in the system on two ways; either registered or hooked. There are plenty of differences between them even though you may not usually notice them. One of them is that hooked hotkeys cannot be triggered by SendInput, and when using SendEvent only when SendLevel is set properly. So in your case, the F8 is likely registered and SC029 would be hooked. You can spend time fixing your script to allow it triggering itself, but I think it would be more direct to just set Status := 2 instead of triggering the hotkey that does so.
javidan
Posts: 3
Joined: 02 May 2018, 10:49

### Re: Add 3 more layers to your keyboard Using these 3 Modifiers - Easy to Program Too!

Thank you guys, so much for this thread.

I was given help in another thread where I was attempting to use SHIFT+SPACE+IJKL to reduce my need to move my hands to the arrow keys and that opened up a whole new can of worms. [Space key is a very bad key to use as a modifier...*ugh*]

I'm still digesting this one. Lack of arrow keys and function keys have been a crippling factor for me to use 75% keyboards but the logic that AHK should be able to free me from the reliance has always been there and I never wrapped my head around it.

So now I'm going to attempt Caps Lock IJKL for arrow keys.