[英]How to simulate shift/ctrl/alt key state?
Does anyone know how I can simulate the shift / ctrl / alt key states? 有谁知道如何模拟shift / ctrl / alt键状态?
Basically I'm creating a remote-desktop app with the clientside using a HTML5 canvas
and the serverside running a C#
app. 基本上我正在创建一个远程桌面应用程序,客户端使用
HTML5 canvas
和运行C#
应用程序的服务器端。 The serverside app captures the screen, sends it and simulates any key presses which were sent by the client. 服务器端应用程序捕获屏幕,发送它并模拟客户端发送的任何按键操作。
I have everything working except the key presses. 除按键外,我的一切都在工作。 The clientside sends:
客户端发送:
kd; KEYCODE HERE
when a key is pressed and 当按下一个键时
ku; KEYCODE HERE
when it's released (keyup). 什么时候发布(keyup)。 I'm using this code:
我正在使用此代码:
[System.Runtime.InteropServices.DllImport("user32.dll")]
static extern void keybd_event(byte bVk, byte bScan, uint dwFlags, int dwExtraInfo);
const int KEYEVENTF_EXTENDEDKEY = 0x1;
const int KEYEVENTF_KEYUP = 0x2;
// - - - - -
// Keyboard events
if (receivedData[0] == "kd")
{
// Shift key pressed
if (receivedData[1] == "16")
{
keybd_event((byte)Convert.ToInt32(Keys.LShiftKey), 0, KEYEVENTF_EXTENDEDKEY, 0);
return;
}
keybd_event((byte)Convert.ToInt32(receivedData[1]), 0, KEYEVENTF_EXTENDEDKEY, 0);
}
if (receivedData[0] == "ku")
{
// Shift key released
if (receivedData[1] == "16")
{
keybd_event((byte)Convert.ToInt32(Keys.LShiftKey), 0, KEYEVENTF_EXTENDEDKEY | KEYEVENTF_KEYUP, 0);
return;
}
keybd_event((byte)Convert.ToInt32(receivedData[1]), 0, KEYEVENTF_EXTENDEDKEY | KEYEVENTF_KEYUP, 0);
}
Normal keys work fine, but any key that has a state won't work correctly. 普通键工作正常,但任何具有状态的键都无法正常工作。 The javascript keycode that's received for left-shift is 16. Any ideas how I would get it working?
为左移收到的javascript键码是16.任何想法我将如何使它工作?
I ended up using the Windows Input Simulator library. 我最终使用Windows输入模拟器库。 Works well for simulating key-downs and key-ups, including the shift, ctrl and alt keys.
适用于模拟按键和按键,包括shift,ctrl和alt键。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.