 |
AutoHotkey Community Let's help each other out
|
| View previous topic :: View next topic |
| Author |
Message |
GeomanNL
Joined: 11 Jun 2006 Posts: 6
|
Posted: Sun Jun 11, 2006 10:14 pm Post subject: keyboard filter |
|
|
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.nl/sjaan.bierman/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.). |
|
| Back to top |
|
 |
Chris Site Admin
Joined: 02 Mar 2004 Posts: 10467
|
Posted: Tue Jun 13, 2006 1:53 am Post subject: |
|
|
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. |
|
| Back to top |
|
 |
GeomanNL
Joined: 11 Jun 2006 Posts: 6
|
Posted: Wed Jun 14, 2006 12:33 pm Post subject: |
|
|
| 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. |
|
| Back to top |
|
 |
Chris Site Admin
Joined: 02 Mar 2004 Posts: 10467
|
Posted: Thu Jun 15, 2006 1:18 am Post subject: |
|
|
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). |
|
| Back to top |
|
 |
GeomanNL
Joined: 11 Jun 2006 Posts: 6
|
Posted: Thu Jun 15, 2006 9:50 am Post subject: |
|
|
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.nl/sjaan.bierman/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. |
|
| Back to top |
|
 |
GeomanNL
Joined: 11 Jun 2006 Posts: 6
|
Posted: Mon Jul 03, 2006 1:56 pm Post subject: |
|
|
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.nl/sjaan.bierman/kbfiltr_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). |
|
| Back to top |
|
 |
MisterW
Joined: 20 Jul 2005 Posts: 65
|
Posted: Thu Jul 06, 2006 12:41 am Post subject: |
|
|
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 |
|
| Back to top |
|
 |
majkinetor
Joined: 24 May 2006 Posts: 3615 Location: Belgrade
|
Posted: Thu Jul 06, 2006 8:05 am Post subject: |
|
|
You can dowload it using P2P software.
I did it using Emulle 1 month from now. _________________
 |
|
| Back to top |
|
 |
Guest
|
Posted: Thu Jul 06, 2006 10:01 am Post subject: |
|
|
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.com/whdc/device/input/Scancode.mspx
Finally, also check the source file WINDDK\inc\wxp\ntddkbd.h to see which variables are in the most important classes. |
|
| Back to top |
|
 |
GeomanNL
Joined: 11 Jun 2006 Posts: 6
|
Posted: Thu Jul 06, 2006 10:02 am Post subject: |
|
|
| (I accidentally posted this as a guest) |
|
| Back to top |
|
 |
PhiLho
Joined: 27 Dec 2005 Posts: 6721 Location: France (near Paris)
|
Posted: Thu Jul 06, 2006 10:55 am Post subject: |
|
|
| GeomanNL wrote: | | (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? _________________
vPhiLho := RegExReplace("Philippe Lhoste", "^(\w{3})\w*\s+\b(\w{3})\w*$", "$1$2") |
|
| Back to top |
|
 |
MisterW
Joined: 20 Jul 2005 Posts: 65
|
Posted: Thu Jul 06, 2006 11:13 am Post subject: |
|
|
| majkinetor wrote: |
I did it using Emulle 1 month from now. |
Back to the future, eh?
I guess you know who won the world cup then...  |
|
| Back to top |
|
 |
GeomanNL
Joined: 11 Jun 2006 Posts: 6
|
Posted: Thu Jul 06, 2006 12:35 pm Post subject: |
|
|
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  |
|
| Back to top |
|
 |
majkinetor
Joined: 24 May 2006 Posts: 3615 Location: Belgrade
|
Posted: Thu Jul 06, 2006 8:28 pm Post subject: |
|
|
2 MisterW
?
No, I don't, I hate football. _________________
 |
|
| Back to top |
|
 |
MisterW
Joined: 20 Jul 2005 Posts: 65
|
Posted: Fri Jul 07, 2006 2:43 am Post subject: |
|
|
| majkinetor wrote: | 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" |
|
| Back to top |
|
 |
|
|
You can post new topics in this forum You can reply to topics in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|