C#中特殊字符键的关键代码? [英] Key code of special charecter keys in C# ?

查看:82
本文介绍了C#中特殊字符键的关键代码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

c#中的特殊字符键码例如



! ,@,#,$,%,^ ----- + =







,. ? /> < ':;}] {[| \ + *



和numpad + - * /





i只需要在c#但是请记住我按160的转换进入特殊的chareceter我有他们在js和vb.net我需要它们在c#



i熟悉这些密钥代码



special charecters keycode in c# for example

! , @ , # , $ , % , ^ ----- + =

and also

, . ? / > < " ' : ; } ] { [ | \ + *

and numpad + - * /


i need then only in c# but remeber i press shift that is 160 to enter special chareceter i have them in js and also vb.net and i need them in c#

i am familiar with these keycodes

if (((Keys)vkCode >= Keys.A && (Keys)vkCode <= Keys.Z) || ((Keys)vkCode >= Keys.OemBackslash && (Keys)vkCode <= Keys.Oemtilde) || (vkCode == 13) || (vkCode <= 106 && vkCode >= 111) || (vkCode <= 105 && vkCode >= 96) || (vkCode <= 106 && vkCode >= 111) || (vkCode <= 57 && vkCode >= 48) || (vkCode == 32))





我尝试过:



i找到了AZ,NUMBERS,NUMPAD,



What I have tried:

i have found the key codes of A-Z , NUMBERS , NUMPAD ,

推荐答案

,%,^ ----- + =







,。 ? /> < ':;}] {[| \ + *



和numpad + - * /





i只需要在c#但是请记住我按160的转换进入特殊的chareceter我有他们在js和vb.net我需要它们在c#



i熟悉这些密钥代码



, % , ^ ----- + =

and also

, . ? / > < " ' : ; } ] { [ | \ + *

and numpad + - * /


i need then only in c# but remeber i press shift that is 160 to enter special chareceter i have them in js and also vb.net and i need them in c#

i am familiar with these keycodes

if (((Keys)vkCode >= Keys.A && (Keys)vkCode <= Keys.Z) || ((Keys)vkCode >= Keys.OemBackslash && (Keys)vkCode <= Keys.Oemtilde) || (vkCode == 13) || (vkCode <= 106 && vkCode >= 111) || (vkCode <= 105 && vkCode >= 96) || (vkCode <= 106 && vkCode >= 111) || (vkCode <= 57 && vkCode >= 48) || (vkCode == 32))





我尝试过的事情:



i找到了AZ,NUMBERS,NUMPAD的关键代码,



What I have tried:

i have found the key codes of A-Z , NUMBERS , NUMPAD ,


I不敢说,即使你的问题确实有意义,它的表述可能是基于对键盘输入的一些误解。你的错误是从关键代码转换为角色。这在概念上是错误的并且可能导致奇怪的错误。

解决方案取决于您使用的UI框架/库,所以我只能给您一些想法。



键盘事件在不同级别处理,从物理键盘的扫描码到字符。您必须明白,当您想要处理键盘事件时,您不应该使用字符。您使用虚拟密钥。您需要了解键盘通常不会生成字符。即使对于固定的键盘布局,许多键与字符完全无关:F1..F12,左,右等。根本没有人物。虚拟键代码为统一按键提供OS抽象层。至于角色,它们出现在下一层,只是处理一些按键的结果,而不是全部。在它发生之前,图中添加了许多因素:当前活动应用程序的当前操作系统版本,区域设置,当前键盘布局(输入语言)已打开。 (每个UI进程都有自己的当前输入语言;您可以按应用程序切换它们,而不是整个桌面。)



通常,.NET UI框架提供 KeyUp KeyDown 处理键盘事件的事件,以及 KeyPress 用于在即将输入字符时处理事件(但可以由应用程序事件处理程序过滤掉)。请参阅有关您在UI框架/库中使用的控件或其他UI元素的文档。您可以覆盖的类似虚拟方法(这是添加事件处理程序的替代方法)具有类似的名称。



我理解一些关键代码或字符,无论您使用什么,在.NET FCL类型中很难找到。找出所需内容的一种简单方法是使用调试器。你写一些处理程序(或它的原型)在它的第一个语句上放置一个断点,并点击所需的键。在调试器下,检查传递给处理程序的事件arguments参数;它将为您提供有关键盘输入的完整信息。



-SA
I afraid to say, even though your question really makes sense, its formulation probably based on some misconception of the keyboard input. Your mistake is the cast from key code to character. This is conceptually wrong and can lead to weird mistakes.
The solution depends on the UI framework/library you are using, so I can only give you some ideas.

Keyboard events are handled in different levels, starting from scan code of the physical keyboard to the characters. You have to understand that when you want to handle keyboard events, you should not work with characters. You work with "virtual keys". You need to understand that the keyboard, generally, does not generate characters. Even for a fixed keyboard layout, many keys are totally unrelated to characters: F1..F12, Left, Right, and so on. No characters at all. Virtual key codes presents the OS abstraction layer for unified key presses. As to the characters, they appear on next layer and only as a result of handling some key presses, not all of them. Before it happens, many factors are added to the picture: current OS version, locale, current keyboard layout (input language) turned on for the current active application. (Each UI process has its own current input language; you switch them on per-application basis, not for the whole desktop.)

Typically, .NET UI frameworks offers KeyUp and KeyDown events for handling keyboard events, and KeyPress for handling the events when a character is about to be entered (but it can be filtered out by your application event handler). Please see the documentation on the controls or other UI elements you are using with your UI framework/library. The analogous virtual methods you can override (this is the approach alternative to adding event handlers) have analogous names.

I understand that some key codes or characters, whatever you use, is hard to find in the .NET FCL types. One simple way to find out what you want is using the debugger. You write some handler (or its prototype) put a break point on its first statement, and hit the desired key. Under the debugger, inspect the event arguments parameter passed to the handler; it will give you complete information on what you can expect from keyboard input.

—SA


这篇关于C#中特殊字符键的关键代码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆