如何在 .Net Compact Framework 3.5 中手动引发系统 KeyDown 事件

发布于 2024-08-27 15:12:36 字数 471 浏览 3 评论 0原文

我在我的应用程序中使用 resco 控件开发了一个自定义键盘我目前已使用以下代码处理了退格按钮单击事件

private void customKeyboard1_KeyboardKeyUp(object sender, Resco.Controls.Keyboard.KeyPressedEventArgs e)
        {
            if (e.Key.Text == "Backspace")
            {
                Resco.Controls.Keyboard.CustomKeyboard.SendBackspace();
                e.Handled = true;
            }
        }

这适用于应用程序中的编辑框,但不适用于网页中的编辑框(例如Gmail 用户名文本框)。

那么有什么方法可以手动引发 KeyDown 事件

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

帅哥哥的热头脑 2024-09-03 15:12:36

P/Invoke PostKeybdMessage

编辑1

大致如下:

[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);
}

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);
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文