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

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

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;


In reply to Re: Remapping Keyboard on Win32 by gryphon
in thread Remapping Keyboard on Win32 by gryphon

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others about the Monastery: (5)
    As of 2020-12-02 08:00 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?
      How often do you use taint mode?





      Results (35 votes). Check out past polls.

      Notices?