是否可以获取“Shift”后的字符?已经按下了,没有按下shift?

发布于 2024-08-16 18:23:54 字数 334 浏览 2 评论 0原文

如果按下“Shift”,是否可以获得字符,也就是说,如果我按“1”,我会得到“1”字符,但如果我按住“Shift”,它会变成“!” - 当然,所有内容都没有引号。我如何以编程方式做这样的事情?

有一种方法可以只添加到 ASCII 代码中。但是,此选项并不合适,因为它不适用于所有区域设置。

是否有一个选项可以在 .NET 中工作,也可能在 Silverlight 中工作,我可以在其中传递像“9”这样的字符并获得结果“(”?

在这种情况下,以编程方式按“Shift”将不起作用,任何 SendKeys 也不起作用由于平台限制,

这适用于虚拟键盘,例如 Silverlight 中的屏幕键盘。

Is it possible to get the character if "Shift" was Pressed, that is, if I press "1" I get the "1" character, but if I hold down "Shift" it becomes "!" - all without the quotes of course. How do I do something like this programatically?

There was a method where you could just add to the ASCII code. However, this option is not suitable as it won't work in every locale.

Is there an option which will work in .NET, and possibly in Silverlight, where I can pass in a character like "9" and get the result "("?

Programmatically pressing "Shift" will not work in this case nor will any SendKeys based solution due to platform limitations.

This would be for a virtual keyboard, like the on-screen keyboard in Silverlight.

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

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

发布评论

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

评论(5

段念尘 2024-08-23 18:23:54

你就不能花几分钟自己制作一个映射表吗?

1->!
2->@
3->#
etc. etc. etc.

Couldn't you just spend a few minutes making a mapping table of your own?

1->!
2->@
3->#
etc. etc. etc.
酒解孤独 2024-08-23 18:23:54

很可能您将不得不做相当多的 API 卑躬屈膝。

您可以从这里开始:
http://msdn.microsoft.com/en-us/library/aa920537。 aspx

更多好读物:
http://www.microsoft.com/globaldev/handson/dev/ unicode-kbdsonwindows.pdf

Odds are you'll have to do quite a bit of API groveling.

You can start here:
http://msdn.microsoft.com/en-us/library/aa920537.aspx

More good reading:
http://www.microsoft.com/globaldev/handson/dev/unicode-kbdsonwindows.pdf

简单爱 2024-08-23 18:23:54

我想返回这个问题:你怎么知道使用什么键盘布局?即,在我的一个系统上,数字 2 带有 @ 符号。另一方面,它有“-符号(双引号)。您说 9 有(-符号,但我的 0 上方有(-符号),减号上方有 )符号

。Windows默认情况下有数百种键盘映射(即乌兹别克西里尔字母、美国国际字母、美国默认字母、荷兰语、德语和德语 IBM 等)。 en.wikipedia.org/wiki/QWERTY" rel="nofollow noreferrer">QWERTY 等等。

真正的问题可能是:如何以编程方式读取 Windows 中的键盘映射。我不知道。虽然它如果您了解如何与驱动程序文件进行交互,那么您可能会更快地使用基于例如我的 上面的第一个链接。当您从注册表中读取键盘类型时,它将涵盖大多数情况。

或者,您可以考虑以编程方式设置 Shift 的粘滞键(设置粘滞键,发送 Shift 键消息即可完成)。

(请注意,ASCII 与键盘扫描代码无关。虽然它可能适用于某些系统,但它永远无法可靠地适用于所有系统。)

编辑:考虑尝试 来自 Microsoft 的键盘布局创建者。遵循它的创建过程和一些逆向工程,不难发现键盘布局是如何编写的。然而,如果您只需要支持一种键盘布局,请在编辑器中使用该键盘布局,反转 Shift 操作,并在有人开始打字之前和之后以编程方式简单地设置新创建的键盘布局(并将其更改回来)。

I'd like to return the question: how do you know what keyboard layout is used? I.e., on one of my systems, the number 2 has the @-sign. On another, it has the "-sign (double quote). You say the 9 has the (-sign, but mine has the (-sign on top of the 0 and the )-sign on top of the minus-sign.

Windows comes by default with hundreds of keyboard mappings (i.e., Uzbek Cyrillic, US International, US Default, Dutch, German and German IBM etc). AZERTY vs QWERTY and so on.

The real question could be: how to read a keyboard mapping in windows programmatically. I don't know. While it will be possible if you find out how you can interface with the driver files, you'll probably be quicker off using a mapping based on, for instance, the layouts in my first link above. When you read the keyboard type from the registry, it'll cover the majority of cases.

Alternatively, you can consider programmatically setting the sticky keys for Shift (set sticky keys, send Shift key message and you're done).

(note that ASCII has nothing to do with keyboard scan codes. While it might've worked for some systems, it'd never have worked reliably for all.)

EDIT: consider trying the keyboard layout creator from Microsoft. Following it's creation process and a bit of reverse engineering, it can't be hard to find out how keyboard layouts are written. Yet, if all you need is support for one keyboard layout, take that one in the editor, reverse the Shift-action and simply programmatically set your newly created keyboard layout (and change it back) before and after someone starts typing.

玩心态 2024-08-23 18:23:54

正是出于这个目的,WPF 和 SilverLight 提供了 TextInput 事件。输入的字符将包含在 TextCompositionEventArgs.Text 属性。该事件已经考虑了用户区域设置和键盘布局:

private void Window_TextInput(object sender, TextCompositionEventArgs e)
{
    // e.Text contains the character that corresponds to the
    // key combination that was pressed
    Trace.WriteLine("TEXT: " + e.Text);
}

这实际上可能无法解决您的问题,因为您特别询问了转换函数。我不知道 WPF/Silverlight 中有这样的函数(有 KeyConverter 类,但其用途不同;您可以使用它来映射数字键和小键盘上的数字键到同一个键)。但是,您必须从某个地方获取按键代码,如果那是键盘,则此事件应该完美执行。

在 Windows 窗体应用程序中(尽管此处似乎不相关),获取实际字符的相应事件将是 Control.KeyPress

For exactly that purpose, WPF and SilverLight offer the TextInput event. The character entered will be contained in the TextCompositionEventArgs.Text property. The event already considers user locale and keyboard layout:

private void Window_TextInput(object sender, TextCompositionEventArgs e)
{
    // e.Text contains the character that corresponds to the
    // key combination that was pressed
    Trace.WriteLine("TEXT: " + e.Text);
}

This actually might not solve your problem, since you specifically asked about a conversion function. I'm not aware of such a function in WPF/Silverlight (There is the KeyConverter class, but its purpose is a different one; you can use it to map both number keys and number keys on the numpad to the same key). However, you must be getting the key codes from somewhere, and if that's the keyboard this event should perfectly do.

In Windows Forms applications (which seems not relevant here though) the corresponding event to get the actual character would be Control.KeyPress.

晨与橙与城 2024-08-23 18:23:54

找到每个字符数字背后的数学并使用它......

find the math in behind the numbers of each character and work with it...

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