Sendkeys.Send() 用于右 alt 键?有什么替代方案吗?

发布于 2025-01-06 19:38:15 字数 280 浏览 4 评论 0原文

我正在开发一个用于触摸屏显示器的 winform 应用程序。 该应用程序由网络浏览器和屏幕键盘组成。 我已经拥有了我需要的大部分东西,但我面临的问题是 有两种输入语言,英语和韩语。 熟悉使用两种语言的任何人都可以告诉您正确的 alt 键 用于在语言之间来回切换。 我需要模拟这个击键,但我找不到任何东西。

我找到了模拟左/右 shift 键和左/右 ctrl 键的方法。 但左/右 alt 键没有任何作用。

我还有其他选择吗?

I am working on a winform app for a touch screen monitor.
The app consists of a web browser and a on screen keyboard.
I have most everything I need, but the problem I am facing is that
there are two input languages, English and Korean.
Anyone familiar with using two languages can tell you that the right alt key
is used to go back and forth between languages.
I need to simulate this keystroke, but I can't find anything for it.

I have found ways to simulate left/right shift keys, and left/right ctrl keys.
But nothing for left/right alt keys.

Do I have any alternatives?

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

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

发布评论

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

评论(4

生来就爱笑 2025-01-13 19:38:15

您可以将 keybd_eventRALT 键码 VK_RMENU 结合使用。完整的键码列表位于此处

您必须P/Invoke 击键如下:

[DllImport("user32.dll", SetLastError = true)] 
static extern void keybd_event(byte bVk, byte bScan, int dwFlags, int dwExtraInfo);  

public const int KEYEVENTF_EXTENDEDKEY = 0x0001; //Key down flag 
public const int KEYEVENTF_KEYUP = 0x0002; //Key up flag 
public const int VK_RMENU = 0xA5;

keybd_event(VK_RMENU, 0, KEYEVENTF_EXTENDEDKEY, 0); 
keybd_event(VK_RMENU, 0, KEYEVENTF_KEYUP, 0); 

You can use keybd_event with RALT keycode VK_RMENU. A complete list of keycodes are here

You would have to P/Invoke the keystroke like this:

[DllImport("user32.dll", SetLastError = true)] 
static extern void keybd_event(byte bVk, byte bScan, int dwFlags, int dwExtraInfo);  

public const int KEYEVENTF_EXTENDEDKEY = 0x0001; //Key down flag 
public const int KEYEVENTF_KEYUP = 0x0002; //Key up flag 
public const int VK_RMENU = 0xA5;

keybd_event(VK_RMENU, 0, KEYEVENTF_EXTENDEDKEY, 0); 
keybd_event(VK_RMENU, 0, KEYEVENTF_KEYUP, 0); 
套路撩心 2025-01-13 19:38:15

您无需模拟 Alt+Shift 击键来更改输入语言。您可以在 System.Windows.Forms 命名空间中使用 InputLanguage 类:

        var currentLang = InputLanguage.CurrentInputLanguage;
        var installedLangs = InputLanguage.InstalledInputLanguages;
        if (installedLangs.Count > 1)
            InputLanguage.CurrentInputLanguage =
                installedLangs[1 - installedLangs.IndexOf(currentLang)];

当您恰好安装了 2 种输入语言时,此代码片段会在这两种语言之间切换。你明白了。正确的?

You don't need to simulate Alt+Shift keystrokes for changing input language. You can use InputLanguage class in System.Windows.Forms namespace:

        var currentLang = InputLanguage.CurrentInputLanguage;
        var installedLangs = InputLanguage.InstalledInputLanguages;
        if (installedLangs.Count > 1)
            InputLanguage.CurrentInputLanguage =
                installedLangs[1 - installedLangs.IndexOf(currentLang)];

When you have exactly 2 input languages installed, this code fragments switches between those two. You get the idea. Right?

岁月打碎记忆 2025-01-13 19:38:15

您并不真的想找到一种发送 Alt 键的方法,对吗?您真正想要的是能够更改输入语言。在这种情况下,请直接前往源头。

Windows API 具有更改当前活动键盘布局的方法。它们不是 .NET Framework 的一部分,但您可以使用 P/Invoke 从 C# 调用它们。

ActivateKeyboardLayout 的 MSDN 文档位于此处

P/Invoke 签名可以在此处找到。

You don't really want to find a way to send the Alt key, right? What you really want is to be able to change the input language. In that case, go straight to the source.

The Windows API has methods to change the current active keyboard layout. They're not part of the .NET Framework, but you can use P/Invoke to call them from C#.

The MSDN documentation for the ActivateKeyboardLayout is here.

And the P/Invoke signatures can be found here.

不乱于心 2025-01-13 19:38:15

MSDN 给出 < code>RMenu 右 alt 的枚举条目。

MSDN gives the RMenu enum entry for right-alt.

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