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

Helpful script writing tricks and HowTo's
survargs
Posts: 6
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

GollyJer
Posts: 18
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: 35
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: 960
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: 35
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: 960
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: 57
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: 960
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: 62
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.

Return to “Tutorials”

Who is online

Users browsing this forum: No registered users and 6 guests