コード例 #1
0
ファイル: MacroManager.cs プロジェクト: Perlucidus/WinMacro
 static MacroManager()
 {
     Macros       = new Dictionary <uint, MacroEntry>();
     LLKH         = new LowLevelKeyboardHook();
     CurrentMacro = new List <uint>();
     MacroLock    = new object();
     try
     {
         string path = $@"{AppData}\{Path}";
         if (File.Exists(path))
         {
             using (BinaryReader data = new BinaryReader(new MemoryStream(File.ReadAllBytes(path))))
             {
                 MacroEntry entry;
                 int        count = data.ReadInt32();
                 for (int i = 0; i < count; i++)
                 {
                     entry = new MacroEntry();
                     entry.Deserialize(data);
                     Macros.Add(entry.Id, entry);
                     NextFreeId = Math.Max(NextFreeId, entry.Id + 1);
                 }
             }
         }
     }
     catch (Exception e)
     {
         Program.MainForm.Notify(e.ToString(), "Loading Error", ToolTipIcon.Error);
     }
     LLKH.KeyboardAction += OnKeyboardAction;
     LLKH.Start();
 }
コード例 #2
0
ファイル: HotkeysManager.cs プロジェクト: Alintya/PoeSuite
        private HotkeysManager()
        {
            var keyboardHook = new LowLevelKeyboardHook(true);
            var mouseHook    = new LowLevelMouseHook(true);

            _hotkeys = new Dictionary <string, HotkeyCommand>();

            foreach (var settings in Properties.Hotkeys.Default.Properties.Cast <SettingsProperty>())
            {
                if (!(Properties.Hotkeys.Default[settings.Name] is VirtualKeyCode keyCode))
                {
                    continue;
                }

                _hotkeys.Add(settings.Name, new HotkeyCommand
                {
                    KeyCode = keyCode
                });

                Logger.Get.Info($"Added hotkey {keyCode} for action {settings.Name}");
            }

            Properties.Hotkeys.Default.PropertyChanged += OnSettingsPropertyChanged;

            keyboardHook.OnKeyboardEvent += OnKeyboardEvent;
            keyboardHook.InstallHook();

            mouseHook.OnMouseEvent += MouseHook_OnMouseEvent;
            mouseHook.InstallHook();

            Messenger.Default.Register <GameActiveStatusChanged>(this, msg =>
            {
                mouseHook.CaptureMouseMove = msg.IsInForeground;
            });
        }
コード例 #3
0
 public LLRecorder()
 {
     llkbHook                      = new LowLevelKeyboardHook();
     llMouseHook                   = new LowLevelMouseHook();
     llkbHook.KeyIntercepted      += new LowLevelKeyboardHook.KeyCallback(llkbHook_KeyIntercepted);
     llMouseHook.MouseIntercepted += new LowLevelMouseHook.MouseCallback(llMouseHook_MouseIntercepted);
     entries = new List <IRecordEntry>();
 }
        public void DisposeWhenNotActivatedTest()
        {
            var hook = new LowLevelKeyboardHook((evnt, data) => { return(LowLevelKeyboardHook.Result.Transfer); });

            Assert.IsFalse(hook.IsActivated);
            hook.Dispose();
            Assert.IsFalse(hook.IsActivated);
        }
        public void ActivatedTest()
        {
            var hook = new LowLevelKeyboardHook((evnt, data) => { return(LowLevelKeyboardHook.Result.Transfer); });

            Assert.IsFalse(hook.IsActivated);
            hook.SetHook();
            Assert.IsTrue(hook.IsActivated);
            hook.Unhook();
            Assert.IsFalse(hook.IsActivated);
        }
コード例 #6
0
        protected override void OnSourceInitialized(EventArgs e)
        {
            base.OnSourceInitialized(e);

            this.keyboardHook = new LowLevelKeyboardHook(PresentationSource.FromVisual(this));
            this.keyboardHook.LowLevelKeyUp += KeyboardHook_LowLevelKeyUp;
            this.keyboardHook.Start();

            // load the window placement details from the user settings.
            SnoopWindowUtils.LoadWindowPlacement(this, Settings.Default.AppChooserWindowPlacement);
        }
コード例 #7
0
ファイル: KeyboardTests.cs プロジェクト: HavenDV/H.Hooks
    public async Task DefaultTest()
    {
        using var cancellationTokenSource = new CancellationTokenSource(TimeSpan.FromSeconds(30));
        var cancellationToken = cancellationTokenSource.Token;

        using var hook = new LowLevelKeyboardHook().WithEventLogging();

        hook.Start();

        await Task.Delay(TimeSpan.FromSeconds(5), cancellationToken);
    }
コード例 #8
0
 public MacroRecorder()
 {
     macroEntries             = new List <MacroRecordEntry>();
     watch                    = new Stopwatch();
     kbHook                   = new LowLevelKeyboardHook();
     msHook                   = new LowLevelMouseHook();
     kbHook.Callback         += new Hook.HookCallback(HookCallback);
     msHook.Callback         += new Hook.HookCallback(HookCallback);
     kbHook.KeyIntercepted   += new LowLevelKeyboardHook.KeyCallback(kbHook_KeyIntercepted);
     msHook.MouseIntercepted += new LowLevelMouseHook.MouseCallback(msHook_MouseIntercepted);
 }
コード例 #9
0
        public void init()
        {
            uiDispatcher = Dispatcher.CurrentDispatcher;
            streamer     = new TobiiStreamer();
            streamer.init();
            streamer.gazePointEvent  += gazePointEvent;
            keyboardHook              = new LowLevelKeyboardHook();
            keyboardHook.onKeyPress   = new LowLevelKeyboardHook.OnKeyPressedDelegate(globalKeyPressHandler);
            keyboardHook.onKeyRelease = new LowLevelKeyboardHook.OnKeyReleasedDelegate(globalKeyReleaseHandler);

            // Necessary to get global cursor? Try removing.
            context.Cursor = new Cursor(Cursor.Current.Handle);
        }
コード例 #10
0
ファイル: KeyboardTests.cs プロジェクト: HavenDV/H.Hooks
    public async Task LeftRightGranularityTest()
    {
        using var cancellationTokenSource = new CancellationTokenSource(TimeSpan.FromSeconds(30));
        var cancellationToken = cancellationTokenSource.Token;

        using var hook = new LowLevelKeyboardHook
              {
                  IsLeftRightGranularity = true,
              }.WithEventLogging();

        hook.Start();

        await Task.Delay(TimeSpan.FromSeconds(5), cancellationToken);
    }
コード例 #11
0
ファイル: Core.cs プロジェクト: david-zaletanski/Arya
        public static void OnApplicationLaunch(string StartupPath)
        {
            // Initialize this classes components.
            PreLoadOutput  = new StringBuilder();
            _PressedKeys   = new List <Keys>();
            exceptionLog   = new StringBuilder();
            llKeyboardHook = new LowLevelKeyboardHook();

            // Initialize other components. Note: Some classes are important to load before main form is loaded.
            Settings = new Settings(StartupPath);
            Settings.LoadSettings(StartupPath + "\\Settings.xml");

            Interface = new frmCLI();
        }
        public void LowLevelKeyboardHookTest()
        {
            var sender = new SingleInputSender();
            var list   = new List <LowLevelKeyboardHook.Event>();
            var hook   = new LowLevelKeyboardHook((evnt, data) => {
                list.Add(evnt);
                return(LowLevelKeyboardHook.Result.Cancel);
            });

            Assert.AreEqual(list.Count, 0);
            hook.SetHook();
            sender.UnicodeKeyStroke("A");
            hook.Unhook();
            Assert.AreEqual(list.Count, 2);
        }
コード例 #13
0
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            LowLevelKeyboardHook kbh = new LowLevelKeyboardHook();

            kbh.OnKeyPressed   += kbh_OnKeyPressed;
            kbh.OnKeyUnpressed += kbh_OnKeyUnpressed;
            kbh.HookKeyboard();

            Application.Run();

            kbh.UnHookKeyboard();
        }
コード例 #14
0
        public static void Main(string[] args)
        {
            LowLevelKeyboardHook kbdHook   = new LowLevelKeyboardHook();
            LowLevelMouseHook    mouseHook = new LowLevelMouseHook();

            kbdHook.OnKeyboardEvent += KbdHook_OnKeyboardEvent;
            mouseHook.OnMouseEvent  += MouseHook_OnMouseEvent;

            kbdHook.InstallHook();
            mouseHook.InstallHook();

            while (true)
            {
                Thread.Sleep(1);
            }
        }
コード例 #15
0
ファイル: KeyboardTests.cs プロジェクト: HavenDV/H.Hooks
    public async Task HandlingTest()
    {
        using var cancellationTokenSource = new CancellationTokenSource(TimeSpan.FromSeconds(30));
        var cancellationToken = cancellationTokenSource.Token;

        using var hook = new LowLevelKeyboardHook
              {
                  Handling = true,
              }.WithEventLogging();
        hook.Up   += (_, args) => args.IsHandled = true;
        hook.Down += (_, args) => args.IsHandled = true;

        hook.Start();

        await Task.Delay(TimeSpan.FromSeconds(5), cancellationToken);
    }
        public void UnhookThrowsInvalidOperationExceptionTestTest()
        {
            var hook = new LowLevelKeyboardHook((evnt, data) => { return(LowLevelKeyboardHook.Result.Transfer); });

            hook.SetHook();
            hook.Unhook();
            try
            {
                hook.Unhook();
            }
            catch (InvalidOperationException)
            {
                return;
            }
            Assert.Fail();
        }
コード例 #17
0
 private void setup()
 {
     STARTING_HEIGHT     = Size.Height;
     ACTUAL_MINIMUM_SIZE = MinimumSize;
     characters_view     = Storage.characters.AsDataView();
     update_filter();
     characters_view.Sort            = "roll DESC, mod DESC, name ASC";
     characters_view.ListChanged    += update_list;
     Storage.active_ids.ListChanged += update_filter;
     keyboard_hook = new LowLevelKeyboardHook();
     keyboard_hook.OnKeyPressed   += global_key_pressed;
     keyboard_hook.OnKeyUnpressed += global_key_unpressed;
     keyboard_hook.HookKeyboard();
     load_cosmetics();
     update_growth_direction();
     Storage.settings.PropertyChanged += handle_settings_changed;
 }
コード例 #18
0
ファイル: Program.cs プロジェクト: zanzo420/LowLevelInput.Net
        static void Main(string[] args)
        {
            TestFilter();

            return;

            // creates a new instance to capture inputs
            // also provides IsPressed, WasPressed and GetState methods
            var inputManager = new InputManager();

            // you may not need those when you use InputManager
            var keyboardHook = new LowLevelKeyboardHook();
            var mouseHook    = new LowLevelMouseHook();

            // subscribe to the events offered by InputManager
            inputManager.OnKeyboardEvent += InputManager_OnKeyboardEvent;
            inputManager.OnMouseEvent    += InputManager_OnMouseEvent;

            // same events as above (in case you only need a specific hook and less functionality)
            keyboardHook.OnKeyboardEvent += KeyboardHook_OnKeyboardEvent;
            mouseHook.OnMouseEvent       += MouseHook_OnMouseEvent;

            // we need to initialize our classes before they fire events and are completely usable
            inputManager.Initialize();
            keyboardHook.InstallHook();
            mouseHook.InstallHook();

            // registers an event (callback) which gets fired whenever the key changes it's state
            // be sure to use this method after the InputManager is initialized
            inputManager.RegisterEvent(VirtualKeyCode.Lbutton, InputManager_KeyStateChanged);

            Console.WriteLine("Waiting for up arrow key to exit!");

            // This method will block the current thread until the up arrow key changes it's state to Down
            // There is no performance penalty (spinning loop waiting for this)
            inputManager.WaitForEvent(VirtualKeyCode.Up, KeyState.Down);

            // be sure to dispose instances you dont use anymore
            // not doing so may block windows input and let inputs appear delayed or lagging
            // these classes try dispose itself when an unhandled exception occurs or the process exits
            mouseHook.Dispose();
            keyboardHook.Dispose();
            inputManager.Dispose();
        }
コード例 #19
0
        public EyeXWinForm(EyeTrackingEngine eyeTrackingEngine, HT.Wimu wimuDevice)
        {
            PseudoTimeStampMiliSecImu = 0;

            InitializeComponent();

            this.eyeTrackingEngine       = eyeTrackingEngine;
            eyeTrackingEngine.GazePoint += this.GazePoint;
            eyeTrackingEngine.OnGetCalibrationCompletedEvent += this.OnGetCalibrationCompleted;
            eyeTrackingEngine.Initialize();

            _llkhk             = new LowLevelKeyboardHook("Low-level Keyboard Hook");
            _llkhk.OnKeyPress += new EventHandler <KeyPressEventArgs>(OnKeyboardHookPress);

            clickDwell = new Dwell();

            this.wimuDevice       = wimuDevice;
            this.head2deltaCursor = new Head2deltaCursor(wimuDevice);
        }
コード例 #20
0
        //The Core off applications is here
        #region SetUp/SetDown/CheckUps/Updates
        private static void SetUp()
        {
            Console.CursorVisible = false;
            Console.Title         = "Senac Clicker GameJam";

            GetData();
            SetUpVars();
            // Disable the Console Edit mode, in way to never lock the main thread during execution due to selections on the window.
            DisableQuickEdit();
            // Initialize Hookers who deal with all the inputs after now.
            KeyboardHook = new LowLevelKeyboardHook();
            MouseHook    = new LowLevelMouseHook();
            // Defines actions to events.
            KeyboardHook.OnKeyboardEvent += KeyboardHook_OnKeyboardEvent;
            MouseHook.OnMouseEvent       += MouseHook_OnMouseEvent;
            // Attach the hookers into main thread.
            KeyboardHook.InstallHook();
            MouseHook.InstallHook();
        }
コード例 #21
0
ファイル: EyeXWinForm.cs プロジェクト: aclemotte/LookAndPlay
        public EyeXWinForm(EyeTrackingEngine eyeTrackingEngine, HT.Wimu wimuDevice)
        {
            PseudoTimeStampMiliSecImu = 0;

            InitializeComponent();

            this.eyeTrackingEngine = eyeTrackingEngine;
            eyeTrackingEngine.GazePoint += this.GazePoint;
            eyeTrackingEngine.OnGetCalibrationCompletedEvent += this.OnGetCalibrationCompleted;
            eyeTrackingEngine.Initialize();

            _llkhk = new LowLevelKeyboardHook("Low-level Keyboard Hook");
            _llkhk.OnKeyPress += new EventHandler<KeyPressEventArgs>(OnKeyboardHookPress);

            clickDwell = new Dwell();

            this.wimuDevice = wimuDevice;
            this.head2deltaCursor = new Head2deltaCursor(wimuDevice);
        }
コード例 #22
0
ファイル: MainForm.cs プロジェクト: zouhao485/mwinapi
 private void timer1_Tick(object sender, EventArgs e)
 {
     timer1.Enabled = false;
     if (llhook)
     {
         kbd   = new LowLevelKeyboardHook();
         mouse = new LowLevelMouseHook();
         kbd.MessageIntercepted   += new LowLevelMessageCallback(ll_MessageIntercepted);
         mouse.MessageIntercepted += new LowLevelMessageCallback(ll_MessageIntercepted);
         kbd.StartHook();
         mouse.StartHook();
     }
     else
     {
         rec              = new JournalRecordHook();
         rec.RecordEvent += new EventHandler <JournalRecordEventArgs>(rec_RecordEvent);
         rec.StartHook();
     }
 }
コード例 #23
0
        private System.Windows.Forms.Timer _updateTime; //must use a timer on the same thread!

        #endregion Fields

        #region Constructors

        public MainForm()
        {
            InitializeComponent();
            //Initialize settings
            preferences = new Preferences();
            _cursorWrapper = new CursorWrapper();
            _logger = new Logger(ref preferences); //load preferences firs5t!

            //Add Keyboard Hook
            kHook = new LowLevelKeyboardHook("kHook");
            kHook.OnKeyDown += new EventHandler<KeyEventArgs>(kHook_OnKeyDown);
            kHook.OnKeyUp += new EventHandler<KeyEventArgs>(kHook_OnKeyUp);

            //Add the Magnifier
            _magnifier = new Magnifier(ref preferences,ref _logger, ref _cursorWrapper);
            _magnifier.Idle += new EventHandler(_magnifier_Idle);

            menuStart.Enabled = !preferences.Study;

            _start = DateTime.Now;
            _updateTime = new System.Windows.Forms.Timer();
            _updateTime.Interval = 1000;
            _updateTime.Tick+=new EventHandler(_updateTime_Tick);
            _updateTime.Enabled = preferences.Logging;

            temp_disable = new System.Windows.Forms.Timer();
            temp_disable.Interval = 300000; //disable for 5 minutes
            temp_disable.Enabled = !preferences.Baseline && preferences.Logging && preferences.Study;
            temp_disable.Tick += new EventHandler(temp_disable_Tick);

            _feedbackReminder = new System.Windows.Forms.Timer();
            _feedbackReminder.Interval = 3600000; //show feedback reminder every hour. Does not neet to be precise
            _feedbackReminder.Enabled = !preferences.Baseline && preferences.Study;
            _feedbackReminder.Tick += new EventHandler(_feedbackReminder_Tick);

            _magnifier.Active = true; //Need to set to true so that the RIM will get initialized properly

            UpdateValues();
        }
コード例 #24
0
        private void Initialize(bool captureMouseMove, bool clearInjectedFlag)
        {
            // initialize vars
            lockObject = new object();

            mapKeyState = new Dictionary <VirtualKeyCode, KeyState>();

            foreach (var pair in KeyCodeConverter.EnumerateVirtualKeyCodes())
            {
                mapKeyState.Add(pair.Key, KeyState.None);
            }

            singleKeyCallback = new Dictionary <VirtualKeyCode, List <KeyStateChangedCallback> >();

            // initialize hooks
            keyboardHook = new LowLevelKeyboardHook(clearInjectedFlag);
            mouseHook    = new LowLevelMouseHook(captureMouseMove, clearInjectedFlag);

            keyboardHook.OnKeyboardEvent += KeyboardHook_OnKeyboardEvent;
            mouseHook.OnMouseEvent       += MouseHook_OnMouseEvent;

            keyboardHook.InstallHook();
            mouseHook.InstallHook();
        }
コード例 #25
0
        public static void Main(string[] args)
        {
            Console.Title = "Init";
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            Console.WriteLine("Directory: ");
            string         dir          = Console.ReadLine();
            InputSimulator simulator    = new InputSimulator();
            FNFSong        song         = null;
            bool           playing      = false;
            Stopwatch      watch        = new Stopwatch();
            int            section      = 0;
            bool           waitingStart = false;

            Console.WriteLine("hooking keyboard shit");

            LowLevelKeyboardHook kbh = new LowLevelKeyboardHook();

            kbh.OnKeyPressed += (sender, keys) =>
            {
                switch (keys)
                {
                case Keys.F1:
                    watch.Reset();
                    watch.Start();
                    playing = true;
                    Console.WriteLine("Started playing...");
                    break;

                case Keys.F2:
                    playing = false;
                    Console.WriteLine("Stopped playing...");
                    waitingStart = false;
                    break;

                case Keys.F3:
                    Console.WriteLine("offset: " + offset);
                    offset++;
                    break;

                case Keys.F4:
                    Console.WriteLine("offset: " + offset);
                    offset--;
                    break;

                case Keys.F5:
                    playing = false;
                    Console.WriteLine("Restarting...");
                    break;
                }
            };
            kbh.HookKeyboard();

            Console.WriteLine("hooked :>");
            int notesPlayed = 0;

            new Thread(() =>
            {
                while (true)
                {
                    Console.Title = "FNFBot 1.1";
                    if (playing)
                    {
                        foreach (FNFSong.FNFSection sect in song.Sections)
                        {
                            List <FNFSong.FNFNote> notesToPlay = new List <FNFSong.FNFNote>();
                            if (sect.Notes.Count == 0)
                            {
                                continue;
                            }

                            if (sect.MustHitSection)
                            {
                                foreach (FNFSong.FNFNote n in sect.Notes)
                                {
                                    if ((int)n.Type >= 4)
                                    {
                                        continue;
                                    }
                                    notesToPlay.Add(n);
                                }
                            }
                            else
                            {
                                foreach (FNFSong.FNFNote n in sect.Notes)
                                {
                                    if ((decimal)n.Type >= 4)
                                    {
                                        notesToPlay.Add(n);
                                    }
                                }
                            }

                            notesPlayed = 0;

                            foreach (FNFSong.FNFNote not in notesToPlay)
                            {
                                new Thread(() =>
                                {
                                    bool shouldHold = not.Length > 0;

                                    if (!playing)
                                    {
                                        Thread.CurrentThread.Abort();
                                    }

                                    Console.WriteLine("Queing " + not.Type + " at " + not.Time);

                                    while ((decimal)watch.Elapsed.TotalMilliseconds < not.Time)
                                    {
                                        Thread.Sleep(1);
                                        if (!playing)
                                        {
                                            Thread.CurrentThread.Abort();
                                        }
                                    }

                                    if (!playing)
                                    {
                                        Thread.CurrentThread.Abort();
                                    }

                                    switch (not.Type)
                                    {
                                    case FNFSong.NoteType.Left:
                                    case FNFSong.NoteType.RLeft:
                                        if (shouldHold)
                                        {
                                            simulator.Keyboard.KeyDown(VirtualKeyCode.LEFT);
                                            Thread.Sleep(Convert.ToInt32(not.Length));
                                            simulator.Keyboard.KeyUp(VirtualKeyCode.LEFT);
                                        }
                                        else
                                        {
                                            KeyPress(0x41, 0x1e);
                                        }

                                        break;

                                    case FNFSong.NoteType.Down:
                                    case FNFSong.NoteType.RDown:
                                        if (shouldHold)
                                        {
                                            simulator.Keyboard.KeyDown(VirtualKeyCode.DOWN);
                                            Thread.Sleep(Convert.ToInt32(not.Length));
                                            simulator.Keyboard.KeyUp(VirtualKeyCode.DOWN);
                                        }
                                        else
                                        {
                                            KeyPress(0x53, 0x1f);
                                        }

                                        break;

                                    case FNFSong.NoteType.Up:
                                    case FNFSong.NoteType.RUp:
                                        if (shouldHold)
                                        {
                                            simulator.Keyboard.KeyDown(VirtualKeyCode.UP);
                                            Thread.Sleep(Convert.ToInt32(not.Length));
                                            simulator.Keyboard.KeyUp(VirtualKeyCode.UP);
                                        }
                                        else
                                        {
                                            KeyPress(0x57, 0x11);
                                        }


                                        break;

                                    case FNFSong.NoteType.Right:
                                    case FNFSong.NoteType.RRight:
                                        if (shouldHold)
                                        {
                                            simulator.Keyboard.KeyDown(VirtualKeyCode.RIGHT);
                                            Thread.Sleep(Convert.ToInt32(not.Length));
                                            simulator.Keyboard.KeyUp(VirtualKeyCode.RIGHT);
                                        }
                                        else
                                        {
                                            KeyPress(0x44, 0x20);
                                        }

                                        break;
                                    }

                                    notesPlayed++;
                                }).Start();
                            }

                            while (notesPlayed != notesToPlay.Count)
                            {
                                Thread.Sleep(1);
                                if (!playing)
                                {
                                    break;
                                }
                            }

                            Console.WriteLine("Going to next section...");
                        }

                        playing      = false;
                        waitingStart = false;
                        Console.WriteLine("Song completed!");
                    }
                    else if (!waitingStart)
                    {
                        watch.Restart();
                        watch.Stop();
                        try
                        {
                            Console.WriteLine("Song Name: ");
                            string name = Console.ReadLine();
                            Console.WriteLine("Diff (none = normal): ");
                            string diff = Console.ReadLine();
                            Console.WriteLine("Trying to load " +
                                              $@"{dir}\assets\data\{name}\{name}{(diff != "" ? "-" + diff : "")}.json");

                            song = new FNFSong(
                                $@"{dir}\assets\data\{name}\{name}{(diff != "" ? "-" + diff : "")}.json");

                            Console.WriteLine("Loaded " + song.SongName + " with " + song.Sections.Count + " sections.");

                            Console.WriteLine("Press F1 to start");
                            waitingStart = true;
                        }
                        catch (Exception e)
                        {
                            Console.WriteLine("Failed to load that song. Exception: " + e);
                        }
                    }
                }
            }).Start();
            Application.Run();
            kbh.UnHookKeyboard();
        }
コード例 #26
0
ファイル: AltTabHook.cs プロジェクト: ogrman/Switcheroo
 public AltTabHook()
 {
     _lowLevelKeyboardHook = new LowLevelKeyboardHook();
     _lowLevelKeyboardHook.MessageIntercepted += OnMessageIntercepted;
     _lowLevelKeyboardHook.StartHook();
 }
コード例 #27
0
ファイル: Program.cs プロジェクト: L-bt2038/FNFBot
        public static void Main(string[] args)
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            Console.WriteLine("Directory: ");
            string         dir       = Console.ReadLine();
            InputSimulator simulator = new InputSimulator();

            Song.Root song         = null;
            bool      playing      = false;
            Stopwatch watch        = new Stopwatch();
            int       section      = 0;
            bool      waitingStart = false;

            Console.WriteLine("hooking keyboard shit");

            LowLevelKeyboardHook kbh = new LowLevelKeyboardHook();

            kbh.OnKeyPressed += (sender, keys) =>
            {
                switch (keys)
                {
                case Keys.F1:
                    watch.Start();
                    playing = true;
                    Console.WriteLine("Started playing...");
                    break;

                case Keys.F2:
                    playing = false;
                    Console.WriteLine("Stopped playing...");
                    waitingStart = false;
                    break;

                case Keys.F3:
                    Console.WriteLine("offset: " + offset);
                    offset++;
                    break;

                case Keys.F4:
                    Console.WriteLine("offset: " + offset);
                    offset--;
                    break;
                }
            };
            kbh.HookKeyboard();

            List <PreAnalize.NoteHit> hit = null;

            Console.WriteLine("hooked :>");

            new Thread(() =>
            {
                while (true)
                {
                    if (playing)
                    {
                        foreach (PreAnalize.NoteHit h in hit)
                        {
                            bool shouldHold = h.length > 0;
                            while (watch.ElapsedMilliseconds < h.time)
                            {
                                if (!playing)
                                {
                                    break;
                                }
                            }
                            if (!playing)
                            {
                                break;
                            }
                            switch (h.type)
                            {
                            case 0:
                                if (shouldHold)
                                {
                                    simulator.Keyboard.KeyDown(VirtualKeyCode.LEFT);
                                    Thread.Sleep(Convert.ToInt32(h.length));
                                    simulator.Keyboard.KeyUp(VirtualKeyCode.LEFT);
                                }
                                else
                                {
                                    KeyPress(VirtualKeyCode.LEFT, simulator);
                                }
                                break;

                            case 1:
                                if (shouldHold)
                                {
                                    simulator.Keyboard.KeyDown(VirtualKeyCode.DOWN);
                                    Thread.Sleep(Convert.ToInt32(h.length));
                                    simulator.Keyboard.KeyUp(VirtualKeyCode.DOWN);
                                }
                                else
                                {
                                    KeyPress(VirtualKeyCode.DOWN, simulator);
                                }

                                break;

                            case 2:
                                if (shouldHold)
                                {
                                    simulator.Keyboard.KeyDown(VirtualKeyCode.UP);
                                    Thread.Sleep(Convert.ToInt32(h.length));
                                    simulator.Keyboard.KeyUp(VirtualKeyCode.UP);
                                }
                                else
                                {
                                    KeyPress(VirtualKeyCode.UP, simulator);
                                }


                                break;

                            case 3:
                                if (shouldHold)
                                {
                                    simulator.Keyboard.KeyDown(VirtualKeyCode.RIGHT);
                                    Thread.Sleep(Convert.ToInt32(h.length));
                                    simulator.Keyboard.KeyUp(VirtualKeyCode.RIGHT);
                                }
                                else
                                {
                                    KeyPress(VirtualKeyCode.RIGHT, simulator);
                                }

                                break;
                            }
                        }
                        playing = false;
                        Console.WriteLine("Song completed!");
                    }
                    else if (!waitingStart)
                    {
                        watch.Restart();
                        watch.Stop();
                        try
                        {
                            Console.WriteLine("Song Name: ");
                            string name = Console.ReadLine();
                            Console.WriteLine("Diff (none = normal): ");
                            string diff = Console.ReadLine();
                            Console.WriteLine("Trying to load " +
                                              $@"{dir}\assets\data\{name}\{name}{(diff != "" ? "-" + diff : "")}.json");

                            song = Song.LoadSong(
                                $@"{dir}\assets\data\{name}\{name}{(diff != "" ? "-" + diff : "")}.json");

                            hit = PreAnalize.Anal(song);

                            Console.WriteLine("Loaded " + song.song.SongSong + " with " + song.sections + " sections.");

                            Console.WriteLine("Press F1 to start");
                            waitingStart = true;
                        }
                        catch (Exception e)
                        {
                            Console.WriteLine("Failed to load that song. Exception: " + e);
                        }
                    }
                }
            }).Start();
            Application.Run();
            kbh.UnHookKeyboard();
        }
コード例 #28
0
 private IntPtr HookCallback(int nCode, IntPtr wParam, IntPtr lParam)
 {
     try { LowLevelKeyboardHook?.Invoke(nCode, wParam, lParam); } catch { }
     return(CallNextHookEx(hookId, nCode, wParam, lParam));
 }