private bool sendKBDInputToQueue(KBDLLHOOKSTRUCT hookStruct) { INPUT input = new INPUT(); input.type = (int)InputType.KEYBOARD; /*input.mkhi.ki.wVk = hookStruct.vkCode; * input.mkhi.ki.wScan = hookStruct.scanCode; * input.mkhi.ki.dwFlags = hookStruct.flags; * input.mkhi.ki.dwExtraInfo = hookStruct.dwExtraInfo;*/ input.mkhi.ki.Vk = 0; input.mkhi.ki.Vk = (ushort)hookStruct.vkCode; input.mkhi.ki.Scan = 0; //input.mkhi.ki.Scan = (ushort)hookStruct.scanCode; input.mkhi.ki.Flags = (uint)hookStruct.flags; input.mkhi.ki.ExtraInfo = new System.IntPtr(hookStruct.dwExtraInfo); INPUT_EXTENDED input_extended = new INPUT_EXTENDED(); input_extended.input = input; MasterGlobalVars.HookingToSocketQueue.Add(input_extended); //Socket.MasterSocket.sendQueuedInput();//TODO use another thread return(true); }
public static void SlaveEnableDisable(int ID, bool enable) { if (!slaves.ContainsKey(ID)) { throw new Exception("ID Slave not available"); } if (enable) { Form1.setIdSlaveFocus(ID); slaves[ID].focused = true; slaves[ID].threadMessage = new Thread(() => sendQueuedInput(ID)); slaves[ID].threadMessage.IsBackground = true; slaves[ID].threadMessage.Start(); INPUT_EXTENDED input_extended = new INPUT_EXTENDED(); input_extended.isNotInput = true; input_extended.focusChange = true; input_extended.focusActivateDeactivate = true; MasterGlobalVars.HookingToSocketQueue.Add(input_extended); } else { if (Form1.getIdSlaveFocus() == ID) { Form1.setIdSlaveFocus(ID); Hooks.MouseListener.blockLocalInput = Hooks.KeyboardListener.blockLocalInput = false; Hooks.MouseListener.blockRemoteInput = Hooks.KeyboardListener.blockRemoteInput = true; } //slaves[ID].focused = false; INPUT_EXTENDED input_extended = new INPUT_EXTENDED(); /* input_extended.focusChange = true; * input_extended.focusActivateDeactivate = false; * MasterGlobalVars.HookingToSocketQueue.Add(input_extended);*/ slaves[ID].focused = false; if (slaves[ID].mustBeDeleted) { return; } input_extended = new INPUT_EXTENDED(); input_extended.not_send = true;//I wake up consumer in order to terminate it(and not consume other INPUT) MasterGlobalVars.HookingToSocketQueue.Add(input_extended); } }
private static void hotkeyFocusToSlave(int ID) { int idOld = Form1.getIdSlaveFocus(); if (idOld != ID) { if (idOld >= 0) { MasterMain.Socket.MasterSocket.SlaveEnableDisable(idOld, false); } MasterMain.Socket.MasterSocket.SlaveEnableDisable(ID, true); } try { INPUT_EXTENDED input_extended = new INPUT_EXTENDED(); input_extended.isNotInput = true; input_extended.focusChange = true; input_extended.focusActivateDeactivate = true; MasterGlobalVars.HookingToSocketQueue.Add(input_extended); } catch (Exception e) { } KeyboardListener.blockLocalInput = true; KeyboardListener.blockRemoteInput = false; MouseListener.blockLocalInput = true; MouseListener.blockRemoteInput = false; }
public static void fullfillHotKeys() { { int[] keys = getCompleteHotkey((int)Keys.M); //{ (int)Keys.LControlKey, (int)Keys.LMenu, (int)Keys.M }; //Keys[] keys = { Keys.K }; HotKeyManager.HotKey hotKey = new HotKeyManager.HotKey(keys, () => { try { INPUT_EXTENDED input_extended = new INPUT_EXTENDED(); input_extended.focusChange = true; input_extended.focusActivateDeactivate = false; input_extended.isNotInput = true; MasterGlobalVars.HookingToSocketQueue.Add(input_extended); foreach (int _key in HotKeyManager.getPrefix()) { int key = _key;//due to bug in some version of C# Form1.getForm().BeginInvoke((Action)(() => WindowsInput.InputSimulator.SimulateKeyUp((WindowsInput.VirtualKeyCode)key))); } } catch (Exception e) { } KeyboardListener.blockLocalInput = false; KeyboardListener.blockRemoteInput = true; MouseListener.blockLocalInput = false; MouseListener.blockRemoteInput = true; }, propagateLastKey: false); KeyboardListener.hkm.insertHotKey(hotKey); } { int[] keys = getCompleteHotkey((int)Keys.S);// { (int)Keys.LControlKey, (int)Keys.LMenu, (int)Keys.S }; //Keys[] keys = { Keys.K }; HotKeyManager.HotKey hotKey = new HotKeyManager.HotKey(keys, () => hotkeyMasterSendClipboard(), propagateLastKey: false); KeyboardListener.hkm.insertHotKey(hotKey); } { int[] keys = getCompleteHotkey((int)Keys.G);// { (int)Keys.LControlKey, (int)Keys.LMenu, (int)Keys.G }; //Keys[] keys = { Keys.K }; HotKeyManager.HotKey hotKey = new HotKeyManager.HotKey(keys, () => hotkeyMasterGetClipboard(), propagateLastKey: false); KeyboardListener.hkm.insertHotKey(hotKey); } /*{ * int[] keys = { (int)Keys.LControlKey, (int)Keys.LMenu, (int)Keys.K }; * //Keys[] keys = { Keys.K }; * HotKeyManager.HotKey hotKey = new HotKeyManager.HotKey(keys, KeyboardListener.toggleLocalKeyInsert); * KeyboardListener.hkm.insertHotKey(hotKey); * } * { * int[] keys = { (int)Keys.LControlKey, (int)Keys.LMenu, (int)Keys.M }; * //Keys[] keys = { Keys.K }; * HotKeyManager.HotKey hotKey = new HotKeyManager.HotKey(keys, MouseListener.toggleLocalMouseInsert); * KeyboardListener.hkm.insertHotKey(hotKey); * } * { * int[] keys = { (int)Keys.LControlKey, (int)Keys.LMenu, (int)Keys.S }; * //Keys[] keys = { Keys.K }; * HotKeyManager.HotKey hotKey = new HotKeyManager.HotKey(keys, () => * { * Socket.MasterSocket.pendingClipboard = true; * INPUT_EXTENDED wake_up = new INPUT_EXTENDED(); * wake_up.not_send = true; * MasterGlobalVars.HookingToSocketQueue.Add(wake_up); * }); * KeyboardListener.hkm.insertHotKey(hotKey); * }*/ }
public static void sendQueuedInput(int ID) { var ns = slaves[ID].ns; if (slaves[ID].mustBeDeleted) { return; } try { //NetworkStream stream = cli.GetStream(); if (ns.CanWrite) { INPUT_EXTENDED input_extended; int numExc = 0; //while (MasterGlobalVars.HookingToSocketQueue.TryDequeue(out input_extended)) while (ns.CanWrite) { try { { Message m = new Message(Message.TypeMessage.Input); input_extended = MasterGlobalVars.HookingToSocketQueue.Take(); //INPUT inputToSend = input_extended.input; m.data = input_extended; if (!input_extended.not_send) { m.WriteToSocket(ns); } if (!slaves[ID].focused) { m = new Message(Message.TypeMessage.Input); input_extended = new INPUT_EXTENDED(); input_extended.focusChange = true; input_extended.focusActivateDeactivate = false; input_extended.isNotInput = true; m.WriteToSocket(ns); return; } } if (MasterGlobalVars.HookingToSocketQueue.Count() > 2) { int a = 1;//debug purpose } if (pendingClipboard && slaves[ID].focused) { /* Message m = new Message(Message.Status.ClipboardAttached);//FIXED * m = CommonClasses.ManageClipboard.getCurrentClipboardMessage(); * m.WriteToSocket(ns); * ns.Flush(); * pendingClipboard = false;*/ } numExc = 0; } catch (Exception e) { numExc++; if (numExc > 4) { slaves[ID].mustBeDeleted = true; slaves[ID].focused = false; Form1.setIdSlaveFocus(-1); Hooks.KeyboardListener.blockLocalInput = false; Hooks.KeyboardListener.blockRemoteInput = true; Hooks.MouseListener.blockLocalInput = false; Hooks.MouseListener.blockRemoteInput = true; return; } } } } } catch (Exception e)//be careful!! è facile creare dipendenze circolari in fase di chiusura { slaves[ID].mustBeDeleted = true; slaves[ID].focused = false; Form1.setIdSlaveFocus(-1); Hooks.KeyboardListener.blockLocalInput = false; Hooks.KeyboardListener.blockRemoteInput = true; Hooks.MouseListener.blockLocalInput = false; Hooks.MouseListener.blockRemoteInput = true; return; } }
/* The specific function that is being used to convert back from normalized coordinates to pixels is equivalent to: * x = trunc(dx*PrimaryScreen.Width/65536) * y = trunc(dy*PrimaryScreen.Height/65536) * * So to make sure that the click arrives at the exact coordinates you desire, you have to convert from pixels to normalized like this: * dx = ceiling(x*65536/PrimaryScreen.Width) * dy = ceiling(y*65536/PrimaryScreen.Height) */ /* * http://stackoverflow.com/questions/8021954/sendinput-doesnt-perform-click-mouse-button-unless-i-move-cursor * */ private bool sendMInputToQueue(MSLLHOOKSTRUCT hookStruct, MouseMessage mouseMessage) { MouseTypeMovement localMouseTypeMovement = mouseTypeMovement; if (!previousXYInitialized) { _previousXY.x = hookStruct.pt.x; _previousXY.y = hookStruct.pt.y; previousXYInitialized = true; } INPUT input = new INPUT(); input.type = (int)InputType.MOUSE; input.mkhi.mi.dwFlags = (uint)hookStruct.flags; if (localMouseTypeMovement == MouseTypeMovement.ABSOLUTE || localMouseTypeMovement == MouseTypeMovement.ABSOLUTE_RESCALED) { input.mkhi.mi.dx = hookStruct.pt.x; input.mkhi.mi.dy = hookStruct.pt.y; } else if (localMouseTypeMovement == MouseTypeMovement.RELATIVE) { input.mkhi.mi.dx = hookStruct.pt.x - _previousXY.x; input.mkhi.mi.dy = hookStruct.pt.y - _previousXY.y; } input.mkhi.mi.mouseData = hookStruct.mouseData; input.mkhi.mi.dwExtraInfo = hookStruct.dwExtraInfo; INPUT_EXTENDED input_extended = new INPUT_EXTENDED(); input_extended.input = input; input_extended.mouseMessage = mouseMessage; input_extended.mouseTypeMovement = localMouseTypeMovement; if (localMouseTypeMovement == MouseTypeMovement.ABSOLUTE_RESCALED) { input_extended.screen_size = _screenSize; } /*if (mouseMessage != MouseMessage.WM_MOUSEMOVE && ((int)mouseMessage) != 0) * { * mouseMessage = mouseMessage; * }*/ //MasterGlobalVars.HookingToSocketQueue.Enqueue(input_extended); //Socket.MasterSocket.sendQueuedInput();//TODO use another thread if (!blockLocalInput) { _previousXY.x = hookStruct.pt.x; _previousXY.y = hookStruct.pt.y; } else { //workaround in order to get deltaXY: the SO inject the new position,but at the end is not accepted..so position remain the same } if (blockRemoteInput) { return(true); } MasterGlobalVars.HookingToSocketQueue.Add(input_extended); return(true); }