Does anyone have tips on simulating the shift/ctrl/alt key states?
I'm currently developing a remote desktop application where the clientside utilizes an HTML5 canvas
and the serverside runs on a C#
app. The serverside part captures the screen, transmits it, and replicates any keystrokes sent by the client.
Everything is functioning properly except for the replication of key presses. The clientside sends:
kd; KEYCODE HERE
when a key is pressed, and
ku; KEYCODE HERE
when it's released (keyup). The code being used is as follows:
[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);
}
While normal keys are working correctly, keys with specific states are causing issues. For instance, the Javascript keycode received for the left-shift key is 16. Any suggestions on how to resolve this issue?