Hi all, I downloaded the windows DDK (device driver kit - for windows XP/SP2) and adapted its keyboard filter template a little. This driver adds the shift+alt key to the stream of keys generated, whenever a key is pressed, and releases the shift+alt as soon as a key is released. .
This is not very useful in itself, but I gave it a try to connect both a USB keyboard, and also a PS/2 keyboard to my computer. These two keyboards have different drivers. If I replace the driver for the PS/2 keyboard with the filter-driver, then whenever I press a key on that keyboard, it will always be accompanied by shift+alt (right-shift and left-alt to be more precise).
This key combination can be intercepted and modified by autohotkey, and turned into some kind of macro, eg with the following script line: "!+a::Send map_A"
I can press A on my usb-keyboard (which has a normal driver) and produce a regular A as output. With the combination of filter driver and autohotkey, I can press A on my ps/2 keyboard and produce the string "map_A".
Whether this is useful or not, is in the eye of the beholder of course.
In case you're interested, the driver + the important part of the source are in this zip file (the driver is in a subdirectory):
http://home.wanadoo....man/kbfiltr.zip
Note that the sample source is only useful in combination with the kbfilter sample in the DDK package.
(ps. I had to hard-code the scan-codes for the alt/shift keys - namely codes 0x036 and 0x038, so it may not work for all keyboards.).

keyboard filter
Started by
GeomanNL
, Jun 11 2006 09:14 PM
48 replies to this topic
#1
-
Posted 11 June 2006 - 09:14 PM

That sounds really cool. There have been quite a few requests to support multiple keyboards/mice, and this seems like a great solution.
Thanks for posting your work and for presenting it so clearly.
Thanks for posting your work and for presenting it so clearly.
#2
-
Posted 13 June 2006 - 12:53 AM

It is probably also possible to modify a key into becoming an extended key, but I don't know if and how autohotkey handles that.
#3
-
Posted 14 June 2006 - 11:33 AM

Extended keys can be distinguished from their non-extended counterparts by the presence of a leading 1 in their scan code (as shown in key history). For example, the down-arrow key is scan code 150, but the down-arrow key on the number pad is 050.
Since most extended scan codes are unused, you could use the SCnnn:: method to create hotkeys out of nonstandard scan codes (ones that you could perhaps generate in your keyboard filter/driver).
Since most extended scan codes are unused, you could use the SCnnn:: method to create hotkeys out of nonstandard scan codes (ones that you could perhaps generate in your keyboard filter/driver).
#4
-
Posted 15 June 2006 - 12:18 AM

Okay, I created a second filter, which doesn't do much except setting the extended-key flag associated with the scan code. With this filter, the second keyboard will always output an extended key.
However, the keys are no longer recognized as normal characters (try typing an extended-a key - it simply won't show up in your editor), so you will have to access them by their scan code.
In the zip file, I included a scancode-test program which I found somewhere on the internet - that one shows you the scancodes in hexadecimal format, of any key that you type. I understand that it's also possible to use the key-history of autohotkey, but that separate program might be more convenient.
If you load a script with a line like this:
"SC102::Send map_02"
it will convert a key press "1" on the keyboard that uses this filter-driver to the string "map_02". That's because key "1" has scan-code 2.
You can find the driver here: http://home.wanadoo....kbfiltr_ext.zip
Note that if the key is already extended, the filter won't make a difference (eg the arrow key you mentioned, but also the right-alt key, will still act like the arrow key and like right-alt), but those cases are uncommon.
Also note, that as far as I can tell, turning normal keys (like A, or Shift) into extended key values, won't conflict with the most "special" commands that windows recognizes - like turning off your computer. I noticed some overlap though - regarding volume control.
However, the keys are no longer recognized as normal characters (try typing an extended-a key - it simply won't show up in your editor), so you will have to access them by their scan code.
In the zip file, I included a scancode-test program which I found somewhere on the internet - that one shows you the scancodes in hexadecimal format, of any key that you type. I understand that it's also possible to use the key-history of autohotkey, but that separate program might be more convenient.
If you load a script with a line like this:
"SC102::Send map_02"
it will convert a key press "1" on the keyboard that uses this filter-driver to the string "map_02". That's because key "1" has scan-code 2.
You can find the driver here: http://home.wanadoo....kbfiltr_ext.zip
Note that if the key is already extended, the filter won't make a difference (eg the arrow key you mentioned, but also the right-alt key, will still act like the arrow key and like right-alt), but those cases are uncommon.
Also note, that as far as I can tell, turning normal keys (like A, or Shift) into extended key values, won't conflict with the most "special" commands that windows recognizes - like turning off your computer. I noticed some overlap though - regarding volume control.
#5
-
Posted 15 June 2006 - 08:50 AM

I've also made a filter for a PS/2 keyboard, which will create letters by typing a certain combination of keys : namely, one of the A,S,D,F keys in combination with one of the the H,J,K,L,Space keys.
This is not directly relevant to autohotkey, but I thought I'd post it here anyway.
Here's the mapping:
asdf --> asdf
hjkl --> hjkl
space --> space
h+asdf --> wxec
j+asdf --> rvtb
k+asdf --> ynum
l+asdf --> giop
space+asdf --> qz,.
There exist special devices which work this way, and which are recommended for anti-rsi. I've never used such a device, but wanted to make something like this using my own keyboard, to see how it "feels".
http://home.wanadoo....filtr_combo.zip
Note that I hard-coded the scan-codes, so this may not work on every keyboard, but us-layouts should be okay, I think.
Edit: note, that the other keys are not affected, so you can type more or less normally as well. Only the asdf hjkl and space keys will behave slightly different (appear only when released, and create different letters when used in combination).
This is not directly relevant to autohotkey, but I thought I'd post it here anyway.
Here's the mapping:
asdf --> asdf
hjkl --> hjkl
space --> space
h+asdf --> wxec
j+asdf --> rvtb
k+asdf --> ynum
l+asdf --> giop
space+asdf --> qz,.
There exist special devices which work this way, and which are recommended for anti-rsi. I've never used such a device, but wanted to make something like this using my own keyboard, to see how it "feels".
http://home.wanadoo....filtr_combo.zip
Note that I hard-coded the scan-codes, so this may not work on every keyboard, but us-layouts should be okay, I think.
Edit: note, that the other keys are not affected, so you can type more or less normally as well. Only the asdf hjkl and space keys will behave slightly different (appear only when released, and create different letters when used in combination).
#6
-
Posted 03 July 2006 - 12:56 PM

Hey GeomanNL
I like where you are going with this.
Could you tell me how you downloaded the DDK? It seems to be available only via msdn subscription.
Do you know if you can build the code using mingw without the DDK?
Any other advice about how you built this would be much appreciated
thanks
I like where you are going with this.
Could you tell me how you downloaded the DDK? It seems to be available only via msdn subscription.
Do you know if you can build the code using mingw without the DDK?
Any other advice about how you built this would be much appreciated
thanks
#7
-
Posted 05 July 2006 - 11:41 PM

You can dowload it using P2P software.
I did it using Emulle 1 month from now.
I did it using Emulle 1 month from now.
#8
-
Posted 06 July 2006 - 07:05 AM

I used msdn subscription, perhaps the p2p works too.
I don't work with mingw; I'm sorry, but can't give advice there.
I used msvc6 to edit the one source file you need to modify.
Then I enter the command-prompt that is included in the DDK, go to the source directory, and type "make". It then compiles and if any, shows errors which I then edit with the other program. It looks a bit clumsy, but the code is so small that it is not a big problem to do it this way.
I had also downloaded the program keytry.exe, to see the scan codes of the keys.
Also, there is the "Keyboard scan code specification" which I read, I think you need to read it before starting. Follow one of the links here:
http://www.microsoft...t/Scancode.mspx
Finally, also check the source file WINDDK\inc\wxp\ntddkbd.h to see which variables are in the most important classes.
I don't work with mingw; I'm sorry, but can't give advice there.
I used msvc6 to edit the one source file you need to modify.
Then I enter the command-prompt that is included in the DDK, go to the source directory, and type "make". It then compiles and if any, shows errors which I then edit with the other program. It looks a bit clumsy, but the code is so small that it is not a big problem to do it this way.
I had also downloaded the program keytry.exe, to see the scan codes of the keys.
Also, there is the "Keyboard scan code specification" which I read, I think you need to read it before starting. Follow one of the links here:
http://www.microsoft...t/Scancode.mspx
Finally, also check the source file WINDDK\inc\wxp\ntddkbd.h to see which variables are in the most important classes.
#9
-
Posted 06 July 2006 - 09:01 AM

Recently, Chris made a change (using JavaScript) to warn when you post as a Guest without nickname.(I accidentally posted this as a guest)
Out of curiosity, did you ignored/missed this warning or did it didn't worked (is this an English sentence?) for you?
#11
-
Posted 06 July 2006 - 09:55 AM


I did it using Emulle 1 month from now.
Back to the future, eh?
I guess you know who won the world cup then... :wink:
#12
-
Posted 06 July 2006 - 10:13 AM

I saw the warning, copied the message text to a file, but I think I've hit enter in the process, and it got posted anyway :oops:
#13
-
Posted 06 July 2006 - 11:35 AM

2 MisterW
?
No, I don't, I hate football.
Sorry, I thought you were implying something about timestamps you weren't.
You meant "I did it using Emule 1 month ago"
#15
-
Posted 07 July 2006 - 01:43 AM
