Ejemplo n.º 1
0
        //hWnd 窗口句柄  //processDic 目标进程目录  //结点信息
        private void PressShortCutInfoKey(string processExePath, KeyTreeNodeTag taginfo)
        {
            foreach (ShortCutInfo info in taginfo.userShortcutMap)
            {
                string processDic     = System.IO.Path.GetDirectoryName(processExePath).ToLower(); //子进程的目录要比父进程的深吧
                string processexeName = System.IO.Path.GetFileName(processExePath);

                string tempDic = System.IO.Path.GetDirectoryName(ShortCutInfo._computerApps[info.AppShowName]).ToLower();
                string tempExe = info.AppShowName;

                Debug.WriteLine(processDic);
                if (processDic.Contains(tempDic))                                       //最前的进程目录要包含定义的目录
                {
                    string sysDicX86 = Environment.GetFolderPath(Environment.SpecialFolder.SystemX86).ToLower();
                    string sysDic    = Environment.GetFolderPath(Environment.SpecialFolder.System).ToLower();
                    if (processDic.Contains(sysDicX86) || processDic.Contains(sysDic))   //如果是系统进程目录内的目录的EXE则要求EXE名称必须相同
                    {
                        if (tempExe != processexeName)
                        {
                            continue;
                        }
                    }

                    if (info.key0 != 0)  //按键消息
                    {
                        if (info.Control0)
                        {
                            Win32APIs.keybd_event(Win32APIs.VK_CONTROL, 0, 0, 0);
                        }
                        if (info.Shift0)
                        {
                            Win32APIs.keybd_event(Win32APIs.VK_SHIFT, 0, 0, 0);
                        }
                        if (info.Alt0)
                        {
                            Win32APIs.keybd_event(Win32APIs.VK_MENU, 0, 0, 0);
                        }
                        Win32APIs.keybd_event(Convert.ToByte(KeyInterop.VirtualKeyFromKey(info.key0)), 0, 0, 0);
                        Win32APIs.keybd_event(Convert.ToByte(KeyInterop.VirtualKeyFromKey(info.key0)), 0, 2, 0);
                        if (info.Alt0)
                        {
                            Win32APIs.keybd_event(Win32APIs.VK_MENU, 0, 2, 0);
                        }
                        if (info.Shift0)
                        {
                            Win32APIs.keybd_event(Win32APIs.VK_SHIFT, 0, 2, 0);
                        }
                        if (info.Control0)
                        {
                            Win32APIs.keybd_event(Win32APIs.VK_CONTROL, 0, 2, 0);
                        }
                        if (info.key1 != 0)
                        {
                            if (info.Control1)
                            {
                                Win32APIs.keybd_event(Win32APIs.VK_CONTROL, 0, 0, 0);
                            }
                            if (info.Shift1)
                            {
                                Win32APIs.keybd_event(Win32APIs.VK_SHIFT, 0, 0, 0);
                            }
                            if (info.Alt1)
                            {
                                Win32APIs.keybd_event(Win32APIs.VK_MENU, 0, 0, 0);
                            }
                            Win32APIs.keybd_event(Convert.ToByte(KeyInterop.VirtualKeyFromKey(info.key1)), 0, 0, 0);
                            Win32APIs.keybd_event(Convert.ToByte(KeyInterop.VirtualKeyFromKey(info.key1)), 0, 2, 0);
                            if (info.Alt1)
                            {
                                Win32APIs.keybd_event(Win32APIs.VK_MENU, 0, 2, 0);
                            }
                            if (info.Shift1)
                            {
                                Win32APIs.keybd_event(Win32APIs.VK_SHIFT, 0, 2, 0);
                            }
                            if (info.Control1)
                            {
                                Win32APIs.keybd_event(Win32APIs.VK_CONTROL, 0, 2, 0);
                            }
                        }
                    }
                }
            }
        }
Ejemplo n.º 2
0
        public void OnProcessDataCompleteEvent(uint flag, object result)
        {
            try
            {
                if (flag == 0x80)
                {//80帧初始化  鼠标用户定义信息初始化
                    ProcessDataComplete80(result);
                }

                if (flag == 0x26)
                {//鼠标键消息处理
                    unsafe
                    {
                        byte[] byteAry = result as byte[];
                        ////垃圾回收过程中可能会把某个对象移动到其它新单元上,垃圾回收器只维护引用信息
                        ////fixed 关键字告诉垃圾回收器,可能有引用某些对象的成员指针,所以这些实例不能移动。变量作用域是fixed块
                        fixed(byte *pBuffer = &(byteAry[0]))
                        {
                            ushort keyType     = *((ushort *)(pBuffer + 4));
                            ushort KeyLastTime = *((ushort *)(pBuffer + 6));
                            //if (KeyLastTime == 0)
                            {
                                IntPtr ptr   = Win32APIs.GetForegroundWindow();
                                IntPtr IDPtr = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(IntPtr)));;
                                Win32APIs.GetWindowThreadProcessId(ptr, IDPtr);
                                Int32 processID = 0;
                                processID = (Int32)Marshal.PtrToStructure(IDPtr, typeof(Int32));
                                Marshal.FreeHGlobal(IDPtr);
                                //Process process = Process.GetProcessById(processID);
                                //Process process = Process.GetProcessById(processID);
                                //string processDic = Path.GetDirectoryName(process.MainModule.FileName);
                                string processExePath = _subForm0.GetProcessWorkPath(processID);
                                switch (keyType)
                                {
                                case GlobalConfig.KEY_TOUCH_LEFT_BIT:    //KEY_TOUCH_LEFT  = 0x01,
                                {
                                    PressShortCutInfoKey(processExePath, touchCntNode.Children[0]._treeTag as KeyTreeNodeTag);
                                }
                                break;

                                case GlobalConfig.KEY_TOUCH_RIGHT_BIT:    //KEY_TOUCH_RIGHT = 0x02,
                                {
                                    PressShortCutInfoKey(processExePath, touchCntNode.Children[1]._treeTag as KeyTreeNodeTag);
                                }
                                break;

                                case GlobalConfig.KEY_TOUCH_MID_BIT:    //KEY_TOUCH_MID   = 0x03,
                                {
                                    PressShortCutInfoKey(processExePath, touchCntNode.Children[2]._treeTag as KeyTreeNodeTag);
                                }
                                break;

                                case GlobalConfig.KEY_TOUCH_UP_BIT:    //KEY_TOUCH_UP    = 0x04,
                                {
                                    PressShortCutInfoKey(processExePath, touchCntNode.Children[3]._treeTag as KeyTreeNodeTag);
                                }
                                break;

                                case GlobalConfig.KEY_TOUCH_DOWN_BIT:    //KEY_TOUCH_DOWN  = 0x05,
                                {
                                    PressShortCutInfoKey(processExePath, touchCntNode.Children[4]._treeTag as KeyTreeNodeTag);
                                }
                                break;

                                case GlobalConfig.KEY_PRESS_LEFT_BIT:    //KEY_PRESS_LEFT  = 0x11,
                                {
                                    PressShortCutInfoKey(processExePath, pressCntNode.Children[0]._treeTag as KeyTreeNodeTag);
                                }
                                break;

                                case GlobalConfig.KEY_PRESS_RIGHT_BIT:    //KEY_PRESS_RIGHT = 0x12,
                                {
                                    PressShortCutInfoKey(processExePath, pressCntNode.Children[1]._treeTag as KeyTreeNodeTag);
                                }
                                break;

                                case GlobalConfig.KEY_PRESS_MID_BIT:    //KEY_PRESS_MID   = 0x13,
                                {
                                    PressShortCutInfoKey(processExePath, pressCntNode.Children[2]._treeTag as KeyTreeNodeTag);
                                }
                                break;

                                case GlobalConfig.KEY_PRESS_UP_BIT:    //KEY_PRESS_UP    = 0x14,
                                {
                                    PressShortCutInfoKey(processExePath, pressCntNode.Children[3]._treeTag as KeyTreeNodeTag);
                                }
                                break;

                                case GlobalConfig.KEY_PRESS_DOWN_BIT:    //KEY_PRESS_DOWN  = 0x15
                                {
                                    PressShortCutInfoKey(processExePath, pressCntNode.Children[4]._treeTag as KeyTreeNodeTag);
                                }
                                break;
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception e)
            {
            }
        }