Commit b4cc24ac authored by Alexander Krause's avatar Alexander Krause

finally... app sends "key up" to webvr mode

parent 9db81128
......@@ -17,81 +17,18 @@ namespace ExplorVizGestureControl.Gestures
{
public class DiscreteGestureDetector
{
[DllImport("user32.dll", EntryPoint = "FindWindow")]
private static extern IntPtr FindWindow(string lp1);
// import the function in your class
[DllImport("User32.dll")]
static extern int SetForegroundWindow(IntPtr point);
[StructLayout(LayoutKind.Sequential)]
private struct KEYBOARD_INPUT
{
public uint type;
public ushort vk;
public ushort scanCode;
public uint flags;
public uint time;
public uint extrainfo;
public uint padding1;
public uint padding2;
}
const uint INPUT_KEYBOARD = 1;
const int KEY_EXTENDED = 0x0001;
const uint KEY_UP = 0x0002;
const uint KEY_SCANCODE = 0x0008;
[DllImport("User32.dll")]
private static extern uint SendInput(uint numberOfInputs, [MarshalAs(UnmanagedType.LPArray, SizeConst = 1)] KEYBOARD_INPUT[] input, int structSize);
void press(int scanCode)
{
sendKey(scanCode, true);
}
void release(int scanCode)
{
sendKey(scanCode, false);
}
private void sendKey(int scanCode, bool press)
{
KEYBOARD_INPUT[] input = new KEYBOARD_INPUT[1];
input[0] = new KEYBOARD_INPUT();
input[0].type = INPUT_KEYBOARD;
input[0].flags = KEY_SCANCODE;
if ((scanCode & 0xFF00) == 0xE000)
{ // extended key?
input[0].flags |= KEY_EXTENDED;
}
if (press)
{ // press?
input[0].scanCode = (ushort)(scanCode & 0xFF);
}
else
{ // release?
input[0].scanCode = (ushort)scanCode;
input[0].flags |= KEY_UP;
}
uint result = SendInput(1, input, Marshal.SizeOf(input[0]));
if (result != 1)
{
throw new Exception("Could not send key: " + scanCode);
}
}
[DllImport("user32.dll", SetLastError = true)]
static extern void keybd_event(byte bVk, byte bScan, int dwFlags, int dwExtraInfo);
#region Variables
private GestureTimer timerForNextGesture;
public Boolean detectContinousGestures = false;
private GestureTimer contDetStartReset;
private const int KEYEVENTF_EXTENDEDKEY = 0x0001; //Key down flag
private const int KEYEVENTF_KEYUP = 0x0002; //Key up flag
private const int UP = 0x26;
#endregion
#region Initialization
......@@ -117,28 +54,12 @@ namespace ExplorVizGestureControl.Gestures
{
case "Start_Reset":
if (contDetStartReset.busy) return;
contDetStartReset.startTimer();
/* sendKey(1,true);
Thread.Sleep(150);
sendKey(1, false);*/
contDetStartReset.startTimer();
try
{
Process[] Processes = Process.GetProcessesByName("chrome");
IntPtr hWnd = IntPtr.Zero;
Debug.Write("Processes: " + Processes.Length + "\n");
foreach (Process p in Processes)
{
Debug.Write("Processes: " + p + "\n");
// do something
hWnd = p.MainWindowHandle;
//SetForegroundWindow(hWnd);
//SendKeys.Send("{UP}");
}
keybd_event(UP, 0, KEYEVENTF_EXTENDEDKEY, 0);
keybd_event(UP, 0, KEYEVENTF_KEYUP, 0);
}
catch (System.InvalidOperationException ex)
{
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment