Няма описание
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. // OS input injection for Windows via user32 SendInput (koffi FFI).
  2. // On non-Windows platforms, exports a stub that logs instead of injecting,
  3. // so the agent can run in dev/test environments.
  4. const { toVirtualKey } = require('./keymap');
  5. const MOUSEEVENTF_MOVE = 0x0001;
  6. const MOUSEEVENTF_ABSOLUTE = 0x8000;
  7. const MOUSEEVENTF_LEFTDOWN = 0x0002;
  8. const MOUSEEVENTF_LEFTUP = 0x0004;
  9. const MOUSEEVENTF_RIGHTDOWN = 0x0008;
  10. const MOUSEEVENTF_RIGHTUP = 0x0010;
  11. const MOUSEEVENTF_MIDDLEDOWN = 0x0020;
  12. const MOUSEEVENTF_MIDDLEUP = 0x0040;
  13. const MOUSEEVENTF_WHEEL = 0x0800;
  14. const KEYEVENTF_KEYUP = 0x0002;
  15. const INPUT_MOUSE = 0;
  16. const INPUT_KEYBOARD = 1;
  17. const BUTTON_DOWN = { 0: MOUSEEVENTF_LEFTDOWN, 1: MOUSEEVENTF_MIDDLEDOWN, 2: MOUSEEVENTF_RIGHTDOWN };
  18. const BUTTON_UP = { 0: MOUSEEVENTF_LEFTUP, 1: MOUSEEVENTF_MIDDLEUP, 2: MOUSEEVENTF_RIGHTUP };
  19. function createWindowsInjector() {
  20. const koffi = require('koffi');
  21. const user32 = koffi.load('user32.dll');
  22. const MOUSEINPUT = koffi.struct('MOUSEINPUT', {
  23. dx: 'long', dy: 'long', mouseData: 'int32',
  24. dwFlags: 'uint32', time: 'uint32', dwExtraInfo: 'uintptr_t',
  25. });
  26. const KEYBDINPUT = koffi.struct('KEYBDINPUT', {
  27. wVk: 'uint16', wScan: 'uint16',
  28. dwFlags: 'uint32', time: 'uint32', dwExtraInfo: 'uintptr_t',
  29. });
  30. const HARDWAREINPUT = koffi.struct('HARDWAREINPUT', {
  31. uMsg: 'uint32', wParamL: 'uint16', wParamH: 'uint16',
  32. });
  33. const INPUT_UNION = koffi.union('INPUT_UNION', {
  34. mi: MOUSEINPUT, ki: KEYBDINPUT, hi: HARDWAREINPUT,
  35. });
  36. const INPUT = koffi.struct('INPUT', { type: 'uint32', u: INPUT_UNION });
  37. const SendInput = user32.func('uint32 SendInput(uint32 cInputs, INPUT *pInputs, int cbSize)');
  38. const INPUT_SIZE = koffi.sizeof(INPUT);
  39. function sendMouse(mi) {
  40. SendInput(1, [{ type: INPUT_MOUSE, u: { mi: