Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re: Remapping Keyboard on Win32

by gryphon (Abbot)
on Mar 24, 2006 at 17:22 UTC ( [id://539067]=note: print w/replies, xml ) Need Help??


in reply to Remapping Keyboard on Win32

Greetings all,

The bad news is that I haven't been able to solve this problem yet. The good news is that my wrist is healing much faster than expected, and I'm now in a smaller splint that frees up my right hand for typing. So I'm abandoning this effort; however, just in case someone else wants to work on this in the future, here's the code I ended up with:

use strict; use warnings; use Win32::API; use Win32::API::Callback; use constant WH_KEYBOARD => 2; use constant LEFT_SHIFT => 0xA0; my $get_thread_id = Win32::API->new('kernel32', 'int GetCurrentThreadI +d()'); my $get_key_state = Win32::API->new('user32', 'GetKeyState', 'I', + 'I'); my $set_hook = Win32::API->new('user32', 'SetWindowsHookEx', 'IKI +I', 'I'); my $call_next = Win32::API->new('user32', 'CallNextHookEx', 'III +I', 'I'); my $unhook_hook = Win32::API->new( 'user32', 'BOOL UnhookWindowsHookEx(int hookHandle)' ); my $hook; my $n = 0; my $callback = Win32::API::Callback->new( sub { $n++; my $next = $call_next->Call($hook, @_); return $next; }, 'III', 'I', ); my $thread_id = $get_thread_id->Call(); print "Thread ID: $thread_id\n"; $hook = $set_hook->Call(WH_KEYBOARD, $callback, 0, $thread_id); for (0 .. 9) { printf "%1d : %3d, %4d\n", $_, $n, $get_key_state->Call( LEFT_SHIFT ) || 0; sleep 1; } my $rv = $unhook_hook->Call($hook);

I primarily used this codefetch.com example along with Win32::API. Although I'm not seeing any errors, I don't think I'm getting the keyboard hook set correctly because $n never increments no matter how many keys I hit while the script runs. The $get_key_state call works just fine, but I can't seem get $callback to get called on keypress. Oh well.

gryphon
Whitepages.com Development Manager (WDDC)
code('Perl') || die;

Replies are listed 'Best First'.
Re^2: Remapping Keyboard on Win32
by Anonymous Monk on Jun 14, 2007 at 15:19 UTC
    Again, in case someone else ends up here, you might want to check out the Scan Code Mapper for Windows. Basically, you add a registry key saying what keys you want to remap. Its simpler than writing anything if your requirements are straightforward. http://www.microsoft.com/whdc/device/input/w2kscan-map.mspx Night

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://539067]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others exploiting the Monastery: (5)
As of 2024-04-24 07:24 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found