Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

keyboard filter


  • Please log in to reply
48 replies to this topic
GeomanNL
  • Members
  • 6 posts
  • Last active: Jan 09 2007 11:40 AM
  • Joined: 11 Jun 2006
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.).

Chris
  • Administrators
  • 10727 posts
  • Last active:
  • Joined: 02 Mar 2004
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.

GeomanNL
  • Members
  • 6 posts
  • Last active: Jan 09 2007 11:40 AM
  • Joined: 11 Jun 2006
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.

Chris
  • Administrators
  • 10727 posts
  • Last active:
  • Joined: 02 Mar 2004
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).

GeomanNL
  • Members
  • 6 posts
  • Last active: Jan 09 2007 11:40 AM
  • Joined: 11 Jun 2006
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.

GeomanNL
  • Members
  • 6 posts
  • Last active: Jan 09 2007 11:40 AM
  • Joined: 11 Jun 2006
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).

MisterW
  • Members
  • 65 posts
  • Last active: Jun 18 2007 11:14 AM
  • Joined: 20 Jul 2005
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

majkinetor
  • Moderators
  • 4512 posts
  • Last active: May 20 2019 07:41 AM
  • Joined: 24 May 2006
You can dowload it using P2P software.

I did it using Emulle 1 month from now.
Posted Image

  • Guests
  • Last active:
  • Joined: --
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.

GeomanNL
  • Members
  • 6 posts
  • Last active: Jan 09 2007 11:40 AM
  • Joined: 11 Jun 2006
(I accidentally posted this as a guest)

PhiLho
  • Moderators
  • 6850 posts
  • Last active: Jan 02 2012 10:09 PM
  • Joined: 27 Dec 2005

(I accidentally posted this as a guest)

Recently, Chris made a change (using JavaScript) to warn when you post as a Guest without nickname.
Out of curiosity, did you ignored/missed this warning or did it didn't worked (is this an English sentence?) for you?
Posted Image vPhiLho := RegExReplace("Philippe Lhoste", "^(\w{3})\w*\s+\b(\w{3})\w*$", "$1$2")

MisterW
  • Members
  • 65 posts
  • Last active: Jun 18 2007 11:14 AM
  • Joined: 20 Jul 2005

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:

GeomanNL
  • Members
  • 6 posts
  • Last active: Jan 09 2007 11:40 AM
  • Joined: 11 Jun 2006
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:

majkinetor
  • Moderators
  • 4512 posts
  • Last active: May 20 2019 07:41 AM
  • Joined: 24 May 2006
2 MisterW
?
No, I don't, I hate football.
Posted Image

MisterW
  • Members
  • 65 posts
  • Last active: Jun 18 2007 11:14 AM
  • Joined: 20 Jul 2005

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"