Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked

Re: Remapping Keyboard on Win32

by gryphon (Abbot)
on Mar 24, 2006 at 17:22 UTC ( #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 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 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. Night

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://539067]
[Corion]: choroba: I'm still using spod5 as my pod-to-ooxml- converter didn't really get off the ground so far
[choroba]: Slidy is basically HTML, so I'm not sure I really fly high :)
choroba should make his presentation scaffolding public
[Corion]: choroba: spod5 converts pod to S5 HTML, so it's also still basic. I find the lack of animations (in the sense of "highlight this", "highlight that" in code) somewhat tedious as I do it with rendered PNGs
[Corion]: I haven't found a good way to include/use the source SVGs I use for creating the PNGs directly as animations
[ambrus]: Presentations come in many different shapes, and so slides do as well.
[Corion]: Doing that in Powerpoint or Ooxml would be nice(r) but I'm much quicker doing the outline of a presentation and the code as Pod

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (13)
As of 2017-09-26 10:01 GMT
Find Nodes?
    Voting Booth?
    During the recent solar eclipse, I:

    Results (293 votes). Check out past polls.