/// <summary>
        /// 键盘信息处理
        /// </summary>
        public void Keyboard_Handler(InputHook v_ih, InputHook.Action action)
        {
            Mouse_Auxiliary_button(v_ih, action);              //检测是否按下鼠标辅助键

            //如果按键是弹起操作,并且弹起的是 左 Alt 键, 并且不是正在模拟的状态,就模拟热键 (如果有需要模拟的热键)
            if (action == InputHook.Action.KeyUp && v_ih.keyboard_Input_Record[0].KeyCode == Keys.LMenu && course.be_simulate == false)
            {
                //如果有快捷键列表窗口弹出,就取选中项为放在Alt要执行的热键
                if (new_Window != null)
                {
                    new_Window.Dispose();                 //释放资源
                    new_Window.Close();                   //关闭窗口
                    new_Window = null;                    //恢复初始值方便下次判断

                    //下面是滚轮触发快捷键的关键
                    if (vHe_Lisy != null)
                    {
                        if (vHe_Lisy.Count != 0)                           //如果窗口不是空的
                        {
                            up_Alt_Execute_HotKey = vHe_Lisy[flpList.Selected_Index];
                        }

                        vHe_Lisy   = null;
                        flpList    = null;
                        new_Window = null;
                    }
                }

                //如果有需要执行的组合键
                if (up_Alt_Execute_HotKey != null)
                {
                    course.be_simulate = true;                    //标记为正在模拟
                    //开始模拟,模拟过程是新线程,把 is_simulated 传过去是方便在新线程中取消正在模拟状态
                    up_Alt_Execute_HotKey.Execute(course);
                    up_Alt_Execute_HotKey = null;
                }
                else
                {
                    course.Reinit();                    //没有要执行的键就重新初始化
                }
            }
        }
Example #2
0
        public KeyStateViewer(InputHook input)
        {
            InitializeComponent();
            if (input != null)
            {
                InputHook = input;
            }
            else
            {
                throw new ArgumentNullException();
            }

            this.Loaded            += (sender, e) => InputHook.Hook();
            InputHook.StateChanged += UpdateKeyState;

            // Stops hook when application closes, avoids null reference exceptions.
            Application.Current.MainWindow.Closing += (sender, args) => Unhook();
            TextBlock.Text = $"{InputHook.Key}";

            CurrentBrush = KeyUpBrush;
        }
Example #3
0
        public void CreateValueWidgetFor(HookAttachment inputWidget, InputHook inputHook)
        {
            GameObject widgetPrefab = FindCorrectValueWidget(inputHook.ValueType);

            object value = inputHook.ValueType.IsValueType ? Activator.CreateInstance(inputHook.ValueType) : null;

            Console.WriteLine(value);

            ValueNode valueNode = new ValueNode().SetPosition(new VectorPosition(0, 0)).SetProgram(ProgramEditor.CurrentEditor.CurrentProgram) as ValueNode;

            valueNode.InitChildren();

            valueNode.SetValue(value).SetType(inputHook.ValueType);

            GameObject newWidget = Instantiate(widgetPrefab, workspace.transform);

            newWidget.transform.position = Input.mousePosition;
            IValueWidget widget = newWidget.GetComponent <IValueWidget> ();

            widget.Initialize(valueNode);
            OnClickedHook(widget.OutputHookWidget);
        }
        /// <summary>
        /// 键盘事件处理
        /// </summary>
        /// <param name="Sender">可以忽略</param>
        /// <param name="key">按键信息</param>
        public void CallBack_KeyboardEvent(InputHook vIh, InputHook.Action Sender)
        {
            v_kma.Keyboard_Handler(vIh, Sender);              //传递给视图辅助窗口

            KeyEventArgs key = vIh.keyboard_Input_Record[0];

            //如果是按弹起键
            if (Sender == InputHook.Action.KeyUp && vHks.is_simulated == false) //使用多线程进行输入辅助处理,不影响主线程
            {
                new MultiThread_InputAuxiliary(vHks);                           //开新线程辅助输入
            }

            System.Threading.Thread.Sleep(1);          //不停不行

            if (WindowState == FormWindowState.Normal) //只有窗口是正常状态才调试输出
            {
                Show_HotKeyState();                    //显示状态键
                if (Sender == InputHook.Action.KeyUp)
                {
                    textBox_foregroundWindowInfo.Text = vHks.window_Info_Foreground.ToString();                     //显示前台窗口信息

                    //显示鼠标所在窗口信息(按右侧 Alt 显示)
                    if (key.KeyCode == Keys.RMenu && Sender == InputHook.Action.KeyUp)
                    {
                        SetFrom_textBox_windowInfo(vHks.window_Info_Mouse.ToString());
                    }
                }
                var v = new {
                    key.KeyValue,
                    key.KeyCode,
                    key.Modifiers,
                    key.SuppressKeyPress
                };
                textBox_foregroundWindowInfo.Text = vHks.window_Info_Foreground.ToString();

                LogWrite(Sender + "\t" + v);
            }
        }
        /// <summary>
        /// 鼠标辅助按键处理
        /// </summary>
        /// <param name="v_ih"></param>
        /// <param name="action"></param>
        private void Mouse_Auxiliary_button(InputHook v_ih, InputHook.Action action)
        {
            if (v_ih.keyStateAll[Keys.LControlKey] == true &&
                v_ih.keyStateAll[Keys.LShiftKey] == true &&
                v_ih.keyStateAll[Keys.LMenu] == true &&
                course.be_execute == false)
            {
                course.Handle    = v_ih.window_Info_Mouse.Root_IntPtr;             //设置鼠标所在窗口句柄
                course.titleName = v_ih.window_Info_Mouse.Root_title.ToString();
                course.className = v_ih.window_Info_Mouse.Root_className.ToString();
                //减号
                if (v_ih.keyStateAll[Keys.Subtract])
                {
                    course.be_execute = true;                  //标记为正在处理
                    set_be_dispose_mouse();                    //500毫秒后设置 be_dispose_mouse 为false

                    up_Alt_Execute_HotKey = vShm.Get_Last(course.titleName, course.className);
                }

                //加号
                if (v_ih.keyStateAll[Keys.Add])
                {
                    course.be_execute = true;                  //标记为正在处理
                    set_be_dispose_mouse();                    //500毫秒后设置 be_dispose_mouse 为false

                    up_Alt_Execute_HotKey = vShm.Get_Next(course.titleName, course.className);
                }
                ////开启一个线程,512毫秒后设置为false
                void set_be_dispose_mouse()
                {
                    new Thread(new ThreadStart(() => {
                        System.Threading.Thread.Sleep(512);
                        course.be_execute = false;                        //标记为正在处理
                    })).Start();
                }
            }
        }
Example #6
0
        public async Task Run()
        {
            Env.Clear();
            Env.Notifier = _notifier;
            Env.App      = new App();
            Env.RandomNumberGenerator = GetRandomNumberGenerator();
            Env.CommandCollection     = new CommandCollection();
            Env.Cipher = new Cipher(await Env.Config.GetKeyAsync());
            Env.StateHandlerFactory = new JsonStateHandlerFactory();
            Env.Settings            = await GetSettingsAsync();

            Env.Parser             = new Parser();
            Env.ModeHook           = new ModeHook();
            Env.ForegroundListener = new ForegroundListener();
            Env.FlagManager        = await FlagManager.GetFlagManagerAsync();

            Env.Scheduler = await Scheduler.GetSchedulerAsync();

            Env.ProcessManager = new ProcessManager();
            Env.Injector       = new Injector();
            Env.PasswordMatrix = await PasswordMatrix.GetPasswordMatrixAsync();

            Env.AccountManager = await AccountManager.GetAccountManagerAsync();

            var comboHook   = new ComboHook();
            var comboRelay  = new ComboRelay(Env.ModeHook, comboHook);
            var inputHook   = new InputHook(comboRelay);
            var inputRelay  = new InputRelay(inputHook);
            var primaryHook = new PrimaryHook(inputRelay);
            var fileManager = await FileManager.GetFileManagerAsync();

            TextEditorForm = new TextEditorForm(fileManager);
            await Env.Config.Run();

            Env.App.TriggerRun();
        }
Example #7
0
 protected virtual void inputHook(InputHook hook)
 {
     return;
 }
 private void CurrentDomainOnUnhandledException(object sender, UnhandledExceptionEventArgs unhandledExceptionEventArgs)
 {
     // Get rid of the keyboard hook in case of a crash, otherwise input freezes up system wide until Artemis is gone
     InputHook.Stop();
 }
 protected override void OnStartup(object sender, StartupEventArgs e)
 {
     DisplayRootViewFor <ShellViewModel>();
     InputHook.Start();
 }
        /// <summary>
        /// 鼠标信息处理
        /// </summary>
        public void Mouse_Handler(InputHook v_ih, MouseEventArgs mea)
        {
            //如果鼠标左键等于按下状态并且鼠标滚轮有滚动,并且不再模拟状态
            if (v_ih.keyStateAll[Keys.LMenu] == true && mea.Delta != 0 && course.be_simulate == false)
            {
                if (course.is_Lock_Handle == false)
                {
                    course.Handle = v_ih.window_Info_Mouse.Root_IntPtr;                    //设置鼠标所在窗口句柄
                }
                //如果窗口已被销毁
                if (new_Window == null)
                {
                    new_Window = new New_Window(new New_Window.Attr_C()
                    {
                        width = new_window_width
                    });

                    new_Window.SuspendLayout();
                    new_Window.Opacity = 0.65;
                    flpList            = new Controls_FlpList(new Controls_FlpList.Attr_C()
                    {
                        width = new_window_width
                    });

                    course.titleName = v_ih.window_Info_Mouse.Root_title.ToString();
                    course.className = v_ih.window_Info_Mouse.Root_className.ToString();
                    vHe_Lisy         = vShm.Get_Key_List(course.titleName, course.className);

                    for (int i = 0; i < vHe_Lisy.Count; i++)
                    {
                        flpList.Add_Record(vHe_Lisy[i].Key_Text, vHe_Lisy[i].comment);
                    }
                    flpList.Selected_Index = 0;                          //设置选中第一条
                    new_Window.Controls.Add(flpList.Flp_list);           //将列表添加到窗口

                    new_Window.ResumeLayout(false);                      //布局相关
                    new_Window.PerformLayout();                          //布局相关

                    new_Window.TopMost = true;                           //窗口在最前

                    new_Window.ControlBox    = false;                    //不显示控制按钮
                    new_Window.ShowInTaskbar = false;                    //不显示在任务栏

                    new_Window.StartPosition = FormStartPosition.Manual; //让窗体的位置由Location属性决定
                    //设置显示位置
                    new_Window.Location = (Point) new Size(
                        mea.Location.X - 10,
                        mea.Location.Y - 10
                        );

                    new_Window.Text = v_ih.window_Info_Mouse.title.ToString(); //设置窗口标题
                    new_Window.Show();                                         //显示窗口
                    SwitchToThisWindow(new_Window.Handle, true);               //窗口置顶
                }

                if (mea.Delta < 0)
                {
                    flpList.Select_UpDown_Item(true);                      //选择下一条
                }
                else
                {
                    flpList.Select_UpDown_Item(false);                      //选择上一条
                }
            }
        }