转换角色,以虚拟键code角色、code

由网友(日光倾城未必温暖)分享简介:我有值的字符串,我想在每个字符的窗口,模拟关键preSS事件。I have a string of values, and I want to simulate key press events in a window for each character.我打算送 WM_KEYDOWN , WM_CHAR 和的...

我有值的字符串,我想在每个字符的窗口,模拟关键preSS事件。

I have a string of values, and I want to simulate key press events in a window for each character.

我打算送 WM_KEYDOWN , WM_CHAR 和的 WM_KEYUP 事件窗口(因为这是似乎发生焕一关键是手动pressed)。

I plan on sending WM_KEYDOWN, WM_CHAR, and WM_KEYUP events to the window (as that is what seems to happen whan a key is manually pressed).

这些消息需要一个int基础上的虚拟键codeS 。我可以通过字符串循环,并获得每一个字符,但我怎么拿该字符并将其转换成相对应的虚拟键code值? Convert.ToInt32()无法正常工作。

Those messages require an int be sent in the wParam based on a table of virtual key codes. I can loop through the string and get each character, but how do I take that character and convert it to a value that corresponds to the virtual key code? Convert.ToInt32() does not work.

推荐答案

发送WM_KEYDOWN / UP麻烦。该应用程序本身就已经平移WM_KEYDOWN消息转换成WM_CHAR,使用组合键(Shift键,Alt键,Ctrl键)以及键盘布局的状态。无论是哪个,你可以控制,你会得到错误的字符,随机。

Sending WM_KEYDOWN/UP is troublesome. The application itself already translates the WM_KEYDOWN message into WM_CHAR, using the state of the modifier keys (Shift, Alt, Ctrl) and the keyboard layout. Neither of which you can control, you'll get the wrong character, randomly.

只需发送WM_CHAR消息,设置WPARAM为字符code。没有必要担心LPARAM,一些应用程序永远使用它。

Just send WM_CHAR messages, set the wparam to the character code. No need to worry about lparam, few apps ever use it.

阅读全文

相关推荐

最新文章