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!

23 Jul 2016, 17:42

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] [Expand] [Download] GeSHi © Codebox Plus



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] [Expand] [Download] GeSHi © Codebox Plus

User avatar
GollyJer
Posts: 45
Joined: 19 Sep 2015, 19:33
GitHub: GollyJer

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

16 Sep 2016, 13:12

EDIT: Decided to post specifically about this.
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] [Download] GeSHi © Codebox Plus

#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?
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!

10 Nov 2016, 10:14

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
Facebook: Acecool
Google: Acecool
GitHub: Acecool
Contact:

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

27 Nov 2016, 11:55

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] [Expand] [Download] GeSHi © Codebox Plus



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.
User avatar
Nextron
Posts: 1102
Joined: 01 Oct 2013, 08:23
Location: Netherlands OS: Win7 x64 AHK: Unicode x32

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

27 Nov 2016, 14:42

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

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] [Download] GeSHi © Codebox Plus

^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] [Download] GeSHi © Codebox Plus

#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.
The more I know:
The more I know,
I know nothing.
Acecool
Posts: 37
Joined: 10 Jan 2016, 18:25
Facebook: Acecool
Google: Acecool
GitHub: Acecool
Contact:

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

06 Dec 2016, 20:43

I seem to have figured it out...

Code: [Select all] [Expand] [Download] GeSHi © Codebox Plus



vs

Code: [Select all] [Expand] [Download] GeSHi © Codebox Plus




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

29 Jan 2017, 12:17

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] [Download] GeSHi © Codebox Plus

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
User avatar
Nextron
Posts: 1102
Joined: 01 Oct 2013, 08:23
Location: Netherlands OS: Win7 x64 AHK: Unicode x32

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

29 Jan 2017, 13:33

The first code fragment from the first post does exactly that.
The more I know:
The more I know,
I know nothing.
iseahound
Posts: 182
Joined: 13 Aug 2016, 21:04
GitHub: iseahound

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

09 Feb 2017, 16:18

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] [Expand] [Download] GeSHi © Codebox Plus



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?
User avatar
Nextron
Posts: 1102
Joined: 01 Oct 2013, 08:23
Location: Netherlands OS: Win7 x64 AHK: Unicode x32

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

09 Feb 2017, 17:27

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! :clap:

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.
The more I know:
The more I know,
I know nothing.
burque505
Posts: 351
Joined: 22 Jan 2017, 19:37

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

19 Feb 2017, 17:26

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!

20 Apr 2018, 11:11

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] [Download] GeSHi © Codebox Plus

#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] [Expand] [Download] GeSHi © Codebox Plus



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.
User avatar
Nextron
Posts: 1102
Joined: 01 Oct 2013, 08:23
Location: Netherlands OS: Win7 x64 AHK: Unicode x32

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

20 Apr 2018, 17:03

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] [Download] GeSHi © Codebox Plus

#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
The more I know:
The more I know,
I know nothing.
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!

Yesterday, 12:57

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] [Download] GeSHi © Codebox Plus

#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!
User avatar
Nextron
Posts: 1102
Joined: 01 Oct 2013, 08:23
Location: Netherlands OS: Win7 x64 AHK: Unicode x32

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

Yesterday, 14:13

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.
The more I know:
The more I know,
I know nothing.

Return to “Tutorials”

Who is online

Users browsing this forum: Mr[Pepparkaka] and 5 guests