Windows 7 Forums
Welcome to Windows 7 Forums. Our forum is dedicated to helping you find support and solutions for any problems regarding your Windows 7 PC be it Dell, HP, Acer, Asus or a custom build. We also provide an extensive Windows 7 tutorial section that covers a wide range of tips and tricks.



Windows 7: Advanced Caps Lock remap

14 Mar 2011   #1

Windows 7 Home Premium 64-bit / Debian Sid 64-bit
 
 
Advanced Caps Lock remap

Hi!


In Debian Sid I have set up my Caps Lock key to open a new browser tab with Google in my default browser unless I have new mail in which case the Caps Lock LED will light up and the mapping will change to GMail.

This is accomplished with a few lines of BASH and some C (full source available if anyone wants it).


Now I'm asking all of the Windows 7 gurus reading this if there's a way to do the same in 7. The LED part is kind of optional, but I need some sort of visual hint if the key is dynamically mapped.

Unfortunately for me the C code isn't very portable as it talks directly to the Linux kernel through the IOCTL interface, meaning I'd have to rewrite major parts of it from scratch (if it can be done easily with standard APIs I might consider it though).


If I have to code or script anything I'll provide the full source and any compiled binaries in return to the forum.


Thanks in advance
/ Djhg2000


Update:
I wrote a script for AutoHotkey Basic to do just what I wanted.
Thanks to everyone here for being so friendly and helpful!

My System SpecsSystem Spec
.

14 Mar 2011   #2

Windows 8 Pro 64-bit
 
 

For one, I'd LOVE to have that source code... xD
Two, I'm quite sure there's a way to do it in 7, you just have to find out how to make everything work together. I'll take a look into it and see what I can find out about the different things involved. Heck, I might even take a crack at doing it myself if I can (Edit: just checked, my usual language has no methods of interfacing with online junk, so nevermind). Then again, you're probably better at programming than I am.
Also, welcome to SevenForums.
My System SpecsSystem Spec
14 Mar 2011   #3

Windows 7 Home Premium 64-bit / Debian Sid 64-bit
 
 

Thank you, but I'm just a hobby programmer so I'd guess my code is pretty far from professional level code

Actually, the mail checking stuff is done by curl in the BASH script (which mostly just glues things together for now) and the C code handles (or rather is supposed to) handle stuff you must do as the root user.

It turns out the curl utility is available for Windows as well (both 32- and 64-bit) in addition to BASH with all of its features which means all that's missing to have an experimental setup would be the key handling.

Turns out Cygwin supports the IOCTL related functions, so I'll have a shot at compiling the unmodified source and report back once that's done. Then all I'll have to do is remap the Caps Lock key to the launcher script and figure out a simple way to handle GUI inputs without the zenity utility (if Cygwin provides this too I'll be so happy!).

So even if there's a Linux emulation layer in there most of the stuff should actually work right off the bat. You might even have the experimental setup up and running by tomorrow if we're lucky!
My System SpecsSystem Spec
.


14 Mar 2011   #4

Windows 7 x64 Ultimate
 
 

It might work within cygwin apps, but it probably won't work for windows in general.

Typically in the past what you had to do was install a lower KB filter driver which you could do whatever you wanted with keystrokes before they entered userland. But Vista and 7 have made that almost impossible because it is like the primary way a keylogger is able to steal your CC#s etc

Best bet is to find a KB that allows you as a matter of the driver to remap keys. Several gaming type KBs have this kind of functionality, though I can't name one that I know for a fact can do this exact thing with that specific key. Logitech gaming KBs have extra fuinction keys you can map to launch programs and such as well.

If you want to actually code this and be able to hand it out to people, I would actually ask this Q in a windows programming forum, like one of the microsoft programing news feeds (search them first). It's going to be a very deep and specific answer. KB filter drivers were a bit trickey in the old XP days. Now it's even worse In order to distribute and hope that it installs on other peoples machines (especially x64 machines) you may even have to get it codesigned. Not fun!
My System SpecsSystem Spec
14 Mar 2011   #5
jav

Windows 7 Ultimate x86 SP1
 
 

Quote   Quote: Originally Posted by fseal View Post
It might work within cygwin apps, but it probably won't work for windows in general.

Typically in the past what you had to do was install a lower KB filter driver which you could do whatever you wanted with keystrokes before they entered userland. But Vista and 7 have made that almost impossible because it is like the primary way a keylogger is able to steal your CC#s etc

Best bet is to find a KB that allows you as a matter of the driver to remap keys. Several gaming type KBs have this kind of functionality, though I can't name one that I know for a fact can do this exact thing with that specific key. Logitech gaming KBs have extra fuinction keys you can map to launch programs and such as well.
I think it is still possible to remap keys within systemwide level (or atleast pseudo-systemwide) with normal KBs
AutoHotkey - Free Mouse and Keyboard Macro Program with Hotkeys and AutoText ?

Not sure about LED part :S

Edit: actually LED can be controlled aswell Keyboard LED control (capslock/numlock/scrolllock lights)
My System SpecsSystem Spec
14 Mar 2011   #6

Windows 8 Pro 64-bit
 
 

^ Was literally just about to post this.
Remapping the keys using AHK's really easy, plus all you'd have to do is just write a very small program that would map the keys and set the LEDs according to the situation.
My System SpecsSystem Spec
14 Mar 2011   #7

Windows 7 Home Premium 64-bit / Debian Sid 64-bit
 
 

Actually I found this:
Keyboard Remapping: CAPSLOCK to Ctrl and Beyond - Scancode Map, registry, keyboard, WM_APPCOMMAND, Flip3D, 3dFlip, Win7, Vista, dwmApi

With a registry hack you can reassign the Caps Lock key to, say, VK_BROWSER_HOME which has the scancode "E0 32". This means the binary key "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Keyboard Layout\Scancode Map" should contain this:
Code:
00 00 00 00 00 00 00 00 02 00 00 00 E0 32 3A 00 00 00 00 00
Now, it so happens that VK_BROWSER_HOME has a reconfigurable action (APPCOMMAND_BROWSER_HOME) and is AppKey 7. This should mean that if we rename the key "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\AppKey\7\Association" to "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\AppKey\7\ShellExecute" and give it the following value:
Code:
"start http://www.google.com"
we should get a nice new tab of Google each time we press caps lock.

At least that's the theory as I have yet to reboot and try it.
Assuming this does work, we can eventually replace that start command with the path to my script which also keeps track of the current new mail status.

To summarize:
  1. Remap Caps Lock to VK_BROWSER_HOME
  2. Replace the default action with the path to my script
  3. Now each time you press the Caps Lock key the script will redirect you to either Google or GMail
  4. Set up some sort of visual hint if you have new mail

Now lets pretend I knew this more than 10 minutes ago

Edit:
I'd like to avoid closed source tools to accomplish this (it's in my nature, I'm a Linux guy after all ) even though that LED stuff looks similar to the IOCTL calls with a 3-bit bitmask for controlling the LEDs.
Now we know it's possible and we just have to figure out how AHK does it.
My System SpecsSystem Spec
14 Mar 2011   #8
jav

Windows 7 Ultimate x86 SP1
 
 

Glad you found a solution. Please report back, how it works out.

The only thing I am missing is how to check mail status, i am sure it is trivial. But I haven't really searched it yet

p.s. If you were reffering to AHK, it is open source and licenced under GNU GPL.
My System SpecsSystem Spec
14 Mar 2011   #9

Windows 7 Home Premium 64-bit / Debian Sid 64-bit
 
 

Quote   Quote: Originally Posted by jav View Post
Glad you found a solution. Please report back, how it works out.

The only thing I am missing is how to check mail status, i am sure it is trivial. But I haven't really searched it yet

p.s. If you were reffering to AHK, it is open source and licenced under GNU GPL.
Actually it didn't work too well, I think I set up the key remap wrong but I can't find where the error is.

On another note, you're right, I found this https://github.com/Lexikos/AutoHotkey_L

Looks like I'll be playing around with AHK for a while
My System SpecsSystem Spec
14 Mar 2011   #10
jav

Windows 7 Ultimate x86 SP1
 
 

I will try to look into it in more details aswell, once I actually get to PC. ( can't realy do anything on phone)

But don't get your expectations too high on me, I am not even amature programmer, I just like experementing with stuff
My System SpecsSystem Spec
Reply

 Advanced Caps Lock remap





Thread Tools



Similar help and support threads for2: Advanced Caps Lock remap
Thread Forum
caps lock problems General Discussion
How to remove Caps Lock Pop-up? General Discussion
Typing in all Caps but Caps lock is disabled - Help Software
Caps lock, num lock, scroll lock screen messages General Discussion
Solved Regarding Caps Lock popup General Discussion
TrayStatus Displays Indicator of Num Lock, Caps Lock, S News
caps lock and the letter L General Discussion

Our Sites

Site Links

About Us

Find Us

Windows 7 Forums is an independent web site and has not been authorized, sponsored, or otherwise approved by Microsoft Corporation. "Windows 7" and related materials are trademarks of Microsoft Corp.

Designer Media Ltd

All times are GMT -5. The time now is 09:36 AM.
Twitter Facebook Google+



Windows 7 Forums

Seven Forums Android App Seven Forums IOS App
  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33