Advanced Caps Lock remap

Page 1 of 3 123 LastLast

  1. Posts : 10
    Windows 7 Home Premium 64-bit / Debian Sid 64-bit
       #1

    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!
    Last edited by Djhg2000; 16 Mar 2011 at 18:43. Reason: Script written
      My Computer


  2. Posts : 799
    Windows 8 Pro 64-bit
       #2

    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 Computer


  3. Posts : 10
    Windows 7 Home Premium 64-bit / Debian Sid 64-bit
    Thread Starter
       #3

    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 Computer


  4. Posts : 2,528
    Windows 7 x64 Ultimate
       #4

    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 Computer


  5. jav
    Posts : 713
    Windows 7 Ultimate x86 SP1
       #5

    fseal said:
    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 Computer


  6. Posts : 799
    Windows 8 Pro 64-bit
       #6

    ^ 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 Computer


  7. Posts : 10
    Windows 7 Home Premium 64-bit / Debian Sid 64-bit
    Thread Starter
       #7

    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 Computer


  8. jav
    Posts : 713
    Windows 7 Ultimate x86 SP1
       #8

    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 Computer


  9. Posts : 10
    Windows 7 Home Premium 64-bit / Debian Sid 64-bit
    Thread Starter
       #9

    jav said:
    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 Computer


  10. jav
    Posts : 713
    Windows 7 Ultimate x86 SP1
       #10

    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 Computer


 
Page 1 of 3 123 LastLast

  Related Discussions
Our Sites
Site Links
About 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 17:46.
Find Us