开发者

How to raise a System KeyDown event manually in .Net Compact framework 3.5

I have developed a custom keypad using resco controls in my application I have currently handled the backspace button click event with the following code

private void开发者_如何学编程 customKeyboard1_KeyboardKeyUp(object sender, Resco.Controls.Keyboard.KeyPressedEventArgs e)
        {
            if (e.Key.Text == "Backspace")
            {
                Resco.Controls.Keyboard.CustomKeyboard.SendBackspace();
                e.Handled = true;
            }
        }

This works fine with the edit boxes in the application but not working in edit boxes in the web pages (for eg. on gmail username text box).

so is there any way to raise the KeyDown event manually


P/Invoke PostKeybdMessage.

EDIT 1

Something along these lines:

[DllImport("coredll.dll", SetLastError = true)]
internal static extern bool PostKeybdMessage(IntPtr hwnd, uint vKey, 
                                             uint flags, uint cCharacters, 
                                             uint[] pShiftStateBuffer, 
                                             uint[] pCharacterBuffer);

private static void SendChar(byte key)
{
    uint KeyStateDownFlag= 0x0080;    
    uint KeyShiftDeadFlag= 0x20000;    
    uint[] buf1 = new uint[] { (uint)key };    
    uint[] DownStates = new uint[] { KeyStateDownFlag };    
    uint[] DeadStates = { KeyShiftDeadFlag };
    PostKeybdMessage(new IntPtr(-1), 0, KeyStateDownFlag, 1, DownStates, buf1);
    PostKeybdMessage(new IntPtr(-1), 0, KeyShiftDeadFlag, 1, DeadStates, buf1);
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜