protected void procHookKeyboard(int code, IntPtr wParam, IntPtr lParam)
        {
            if (code != 0)
            {
                return;
            }
            if (evnHook != null)
            {
                Keys          key       = (Keys)lParam.ToInt32();
                HookEventArgs eventArgs = new HookEventArgs();
                eventArgs.type     = m_hookType;
                eventArgs.lParam   = lParam;
                eventArgs.wParam   = wParam;
                eventArgs.HookCode = code;

                eventArgs.WMessages = (WindowsMessages)wParam;
                eventArgs.bAltKey   = GetKeyState(VirtualKeys.VK_MENU) <= -127;
                eventArgs.bCtrlKey  = GetKeyState(VirtualKeys.VK_CONTROL) <= -127;
                KBLLHOOKSTRUCT theKeyBordInfo = (KBLLHOOKSTRUCT)Marshal.PtrToStructure(lParam, typeof(KBLLHOOKSTRUCT));
                eventArgs.key = (Keys)theKeyBordInfo.wVk;
                CDebug.jmsg("[Keyboard][{0}] X:{1} Y:{2}=>{3} ", eventArgs.WMessages.ToString(), eventArgs.bAltKey, eventArgs.bCtrlKey, (Keys)theKeyBordInfo.wVk);
                evnHook(this, eventArgs);
            }
            return;
        }
 public void stop()
 {
     if (dispatcherTimer == null)
     {
         CDebug.jmsg("★★★[Err]★★★dispatcherTimer[{0}] == null", m_strTimerName);
     }
     if (dispatcherTimer != null)
     {
         dispatcherTimer.Stop();
     }
 }
 public void NotifyModelChanged()
 {
     if (calbkEventTimeup == null)
     {
         CDebug.jmsg("★★★[Err]★★★NotifyModelChanged[{0}] == null", m_strTimerName);
     }
     if (calbkEventTimeup != null)
     {
         calbkEventTimeup(this, new EventArgs());
     }
 }
 public void start()
 {
     if (dispatcherTimer == null)
     {
         CDebug.jmsg("★★★[Err]★★★dispatcherTimer[{0}] == null", m_strTimerName);
     }
     if (dispatcherTimer != null)
     {
         dispatcherTimer.Start();
         CDebug.jmsg("★★★dispatcherTimer.Start({0})=>{1}s", m_strTimerName, m_nEventDurationSec);
     }
 }
 protected void CallProcHookProcedure(int code, IntPtr wParam, IntPtr lParam)
 {
     if (evnHook != null)
     {
         HookEventArgs eventArgs = new HookEventArgs();
         eventArgs.type     = m_hookType;
         eventArgs.lParam   = lParam;
         eventArgs.wParam   = wParam;
         eventArgs.HookCode = code;
         CDebug.jmsg("[OtherHook] lParam:{0} wParam:{1} HookCode:{2}", eventArgs.lParam, eventArgs.wParam, eventArgs.HookCode);
         evnHook(this, eventArgs);
     }
     return;
 }
        protected virtual void Dispose(bool disposing)
        {
            bool ret = false;

            if (isHooking == true)
            {
                ret = UnhookWindowsHookEx(hookHandle);

                hookHandle = IntPtr.Zero;
                if (ret == false)
                {
                    CDebug.jmsg("呼叫 UnhookWindowsHookEx 失敗!");
                }
            }
        }
 void TimerCount_Tick(object sender, EventArgs e)
 {
     if (m_nEventDurationSec > 0)
     {
         m_nEventDurationSec--;
     }
     else if (m_nEventDurationSec <= 0)
     {
         dispatcherTimer.Stop();
         CDebug.jmsg("[DispatcherTimer][{0}]時間到,呼叫註冊的函式....", m_strTimerName);
         if (calbkEventTimeup != null)
         {
             NotifyModelChanged();
         }
     }
 }
        /// <summary>
        /// string ARGB => System.Windows.Media.Brush
        /// </summary>
        /// <param name="strColorCode"></param>
        /// <returns></returns>
        public static System.Windows.Media.Brush colorConvert2BrushByColorCode(string strColorCode)
        {
            BrushConverter bc = new BrushConverter();

            //return (System.Windows.Media.Brush)bc.ConvertFrom(strColorCode);
            //if (strColorCode.Substring(0, 1).CompareTo("#") == 0)//可以直接輸入字串ARGB值 "#FFADFF"
            try
            {
                return((System.Windows.Media.Brush)bc.ConvertFromString(strColorCode));
            }
            catch (Exception e)
            {
                CDebug.jmsg("[colorConvert2BrushByColorCode]err: [{0}]", e.ToString());
                return(null);
            }
        }
Example #9
0
        private void procEventLoop()
        {
            while (m_stop == false)
            {
                SpinWait.SpinUntil(() => listEventData.Count > 0 || m_stop == true, -1);
                if (m_stop == true)
                {
                    break;
                }
                if (listEventData.Count > 0)
                {
                    //取得第一筆資料
                    CEventInfo _cTaskInof = new CEventInfo(4294967295);///初始化UInt32最大值
                    Monitor.Enter(listEventData);
                    _cTaskInof = listEventData[0];
                    listEventData.RemoveAt(0);
                    if (_cTaskInof == null)
                    {
                        continue;
                    }

                    Monitor.Enter(listEventData);

                    InvokeDelegate fnProcThis;
                    try
                    {
                        if (listProcFuncitons.TryGetValue(_cTaskInof.nEventCode, out fnProcThis))
                        {
                            Thread thProcEvent = new Thread(() => fnProcThis(_cTaskInof));
                            thProcEvent.SetApartmentState(ApartmentState.STA); //Set the thread to STA
                            thProcEvent.Start();
                        }
                        else
                        {
                            CDebug.jmsg("[錯誤]處理事件:{0}未設定處理函式\n", _cTaskInof.nEventCode);
                            continue;
                        }
                    }
                    catch (Exception e)
                    {
                        CDebug.jmsgEx("[EventPorc]Exception!!{0}", e.Message);
                        continue;
                    }
                }
            }
        }
Example #10
0
        public static void jlog(string log_string, params Object[] args)
        {
            if (_flog == null)
            {
                initFileLogger();
            }
            updateFileNamebyDate();
            if (!File.Exists(m_strFullFilePath))                                   ///更換日期
            {
                string logPathname = System.Windows.Forms.Application.StartupPath; //執行程式的路徑;//Directory.GetCurrentDirectory();
                if (m_FileLogName == null)
                {
                    m_strFullFilePath = string.Format("{0}\\[{1:0000}_{2:00}_{3:00}]{4}.log", logPathname,
                                                      DateTime.Today.Year, DateTime.Today.Month, DateTime.Today.Day, m_strLogFileName);
                }
                else
                {
                    m_strFullFilePath = string.Format("{0}\\[{1:0000}_{2:00}_{3:00}]{4}_{5}.log", logPathname,
                                                      DateTime.Today.Year, DateTime.Today.Month, DateTime.Today.Day, m_strLogFileName, m_FileLogName);
                }
                _flog = File.CreateText(m_strFullFilePath);
            }
            string strMsg2Log;

            if (args.Length <= 0)
            {
                strMsg2Log = log_string;
            }
            else
            {
                strMsg2Log = string.Format(log_string, args);
            }
            _flog.WriteLine("[" + DateTime.Now.ToString("HH:mm:ss") + "]> " + strMsg2Log);
            _flog.Flush();

            if (T_DEBUG == true)
            {
                CDebug.jmsg("{0}", strMsg2Log);
            }
        }