转换角色,以虚拟键code [英] Convert character to virtual key code

查看:154
本文介绍了转换角色,以虚拟键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 和的 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.

这篇关于转换角色,以虚拟键code的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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