RE: Keyboard event handler to ignore repeated key_down, key_up

Tech-Archive recommends: Fix windows errors by optimizing your registry



I have a few problems compiling this code. Perhaps I do not have the correct
P/invoke method signature.

1) your method: IntPtr MyCallbackFunction
my method: int MyCallbackFunction (my CallNextHookEx returns an int)
Question: are the two equivalent? Should I change my method signatures?

2) your call: BitVector32 myBV = new BitVector32( lParam);
Problem: This does not compile, I need to pass in lParam.toInt32()
Question: Was this just a typo or do I need to do something different?

3) your call: lParam.ToString("X");
Problem: The ToString() methods I am exposed to do not take any arguments.
Question: What does the "X" mean? What does ToString("X") return?

4) Can you please tell me what the following are testing for?
bool rt = ((lParam& 0x40000000)==0x40000000);
((lParam & 0x80000000)==0x80000000);

5) My code accesses bitvector[30] but this continually returns false
Question: Is this a known issue as well?

Thank you for your help.

""Peter Huang" [MSFT]" wrote:

> Hi
>
> Your approach, but there is a known issue when we access one bit.
> We can use the code below to replace the original code.
>
> private IntPtr MyCallbackFunction(int code, int wParam, int lParam)
> {
>
> Debug.WriteLine("=====================start=================================
> =");
> if (code < 0)
> {
> //you need to call CallNextHookEx without further processing
> //and return the value returned by CallNextHookEx
> return CallNextHookEx(IntPtr.Zero, code, wParam, lParam);
> }
>
> Debug.WriteLine("0x"+lParam.ToString("X"));
> BitVector32 myBV = new BitVector32( lParam);
> BitVector32.Section mySect1 = BitVector32.CreateSection( short.MaxValue );
>
> // we can convert the 2nd parameter (the key code) to a
> System.Windows.Forms.Keys enum constant
> Keys keyPressed = (Keys)wParam;
> Debug.WriteLine(keyPressed);
> Debug.WriteLine(myBV[mySect1].ToString("X"));
> bool rt = ((lParam& 0x40000000)==0x40000000);
> Debug.WriteLine(rt.ToString());
> Debug.WriteLine(((lParam & 0x80000000)==0x80000000));
> //return the value returned by CallNextHookEx
>
> Debug.WriteLine("=====================end=================================="
> );
> return CallNextHookEx(IntPtr.Zero, code, wParam, lParam);
> }
>
>
> From the MSDN document, commonly the repeat count is 1.
> Repeat Count
> You can check the repeat count to determine whether a keystroke message
> represents more than one keystroke. The system increments the count when
> the keyboard generates WM_KEYDOWN or WM_SYSKEYDOWN messages faster than an
> application can process them. This often occurs when the user holds down a
> key long enough to start the keyboard's automatic repeat feature. Instead
> of filling the system message queue with the resulting key-down messages,
> the system combines the messages into a single key down message and
> increments the repeat count. Releasing a key cannot start the automatic
> repeat feature, so the repeat count for WM_KEYUP and WM_SYSKEYUP messages
> is always set to 1.
>
> But the 30th bit will be useful to identify the repeat.
> Previous Key-State Flag
> The previous key-state flag indicates whether the key that generated the
> keystroke message was previously up or down. It is 1 if the key was
> previously down and 0 if the key was previously up. You can use this flag
> to identify keystroke messages generated by the keyboard's automatic repeat
> feature. This flag is set to 1 for WM_KEYDOWN and WM_SYSKEYDOWN keystroke
> messages generated by the automatic repeat feature. It is always set to 0
> for WM_KEYUP and WM_SYSKEYUP messages.
>
> http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/winui
> /windowsuserinterface/userinput/keyboardinput/aboutkeyboardinput.asp
>
>
> Best regards,
>
> Peter Huang
> Microsoft Online Partner Support
>
> Get Secure! - www.microsoft.com/security
> This posting is provided "AS IS" with no warranties, and confers no rights.
>
>
.



Relevant Pages

  • RE: Keyboard event handler to ignore repeated key_down, key_up
    ... commonly the repeat count is 1. ... > You can check the repeat count to determine whether a keystroke message ... > key long enough to start the keyboard's automatic repeat feature. ... > The previous key-state flag indicates whether the key that generated the ...
    (microsoft.public.office.developer.com.add_ins)
  • RE: Keyboard event handler to ignore repeated key_down, key_up
    ... commonly the repeat count is 1. ... You can check the repeat count to determine whether a keystroke message ... key long enough to start the keyboard's automatic repeat feature. ... The previous key-state flag indicates whether the key that generated the ...
    (microsoft.public.office.developer.com.add_ins)
  • [PATCH] ATI Remote Control improvements
    ... module_param(debug, int, 0444); ... +static int selectiverepeat; ... * FILTER_TIME jiffies between them are considered as repeat ... keyrepeats, don't simulate repeat */ ...
    (Linux-Kernel)
  • Re: macros (was: Paul Grahams teaching style is bad}
    ... I just had not known `repeat ... ... main (int argc, char *argv) ... > example, that expands to arbitrarily nested for loops, with the depth ... > depending on the way the user uses the macro. ...
    (comp.lang.lisp)
  • Re: Update blip???
    ... If I go to preferences keyboard and check Key presses repeat when key is ... key press provides an immediate two characters. ... The gnome schema says int, but the %gconfig.xml file in my directory ...
    (Fedora)