private static void startMagnifier() { if (magnifierWindowLens == null) { magnifierWindowLens = new magnifier(true); magnifierWindowLens.Show(); mgnLens = new Karna.Magnification.Magnifier(magnifierWindowLens, true); mgnLens.Magnification = (float)(Properties.Settings.Default.magnificationRate + 2.0) / 2; } /* else if(magnifierWindowDocked==null) * { * //System.Windows.MessageBox.Show("This is Docked"); * magnifierWindowDocked = new magnifier(Properties.Settings.Default.isLens); * magnifierWindowDocked.Show(); * mgnDocked = new Magnifier(magnifierWindowDocked, Properties.Settings.Default.isLens); * mgnDocked.Magnification = (float)(Properties.Settings.Default.magnificationRate + 2.0) / 2; * } */ }
public static IntPtr hookProc(int code, IntPtr wParam, IntPtr lParam) { #region // keydown hooking if (code >= 0 && wParam == (IntPtr)WM_KEYDOWN) { int vkCode = Marshal.ReadInt32(lParam); if (vkCode.ToString() == "124") // 38: up key, 81: q key, 124: F13 key(shift+F1) // http://crynut84.tistory.com/34 참조 { #region /*stop watch for magnification*/ if (SW.ElapsedMilliseconds > 200) { SW.Stop(); Timer_Tick(); SW.Reset(); } if (!SW.IsRunning) { SW.Start(); } #endregion #region if (flag_mag_start) { return((IntPtr)1); } else { switch (mouseEvent_var) { case (int)mouseEvent.LCLICKED: mouse_event(LEFTDOWN, 0, 0, 0, 0); // 마우스 왼쪽 클릭 return((IntPtr)1); //return 1: vkCode(up 키) 메세지를 메세지 큐로 전달하지 않음 (=up 키가 작동되지 않음) // return CallNextHookEx(hhook, code, (int)wParam, lParam); //: 해당 메세지를 큐로 전달함 case (int)mouseEvent.RCLICKED: mouse_event(RIGHTDOWN, 0, 0, 0, 0); // 마우스 오른쪽 클릭 return((IntPtr)1); // return CallNextHookEx(hhook, code, (int)wParam, lParam); //: 해당 메세지를 큐로 전달함 case (int)mouseEvent.DOUBLECLICKED: mouse_event(LEFTDOWN, 0, 0, 0, 0); // 마우스 더블 클릭 return((IntPtr)1); case (int)mouseEvent.DRAGCLICKED: mouse_event(LEFTDOWN, 0, 0, 0, 0); // 마우스 드래그 return((IntPtr)1); case (int)mouseEvent.RELEASED: mouse_event(LEFTUP, 0, 0, 0, 0); mouseEvent_var = (int)mouseEvent.LCLICKED; return((IntPtr)1); } } #endregion } #region //when user coordinates gaze Point and mouse position. if (isCoordinate) { switch (vkCode) { //A key- 왼쪽으로 좌표점 이동시키기 case 65: userCoordinateX -= 5; break; //D key - 오른쪽으로 좌표점 이동시키기 case 68: userCoordinateX += 5; break; //W key - 위로 이동시키기 case 87: userCoordinateY -= 5; break; //S key - 아래로 이동시키기 case 83: userCoordinateY += 5; break; default: break; } return((IntPtr)1); } else { return(CallNextHookEx(hhook, code, (int)wParam, lParam)); } #endregion } #endregion #region //keyup hooking else if (code >= 0 && wParam == (IntPtr)WM_KEYUP) { int vkCode = Marshal.ReadInt32(lParam); if (vkCode.ToString() == "124") // 38: up key, 81: q key, 124: F13 key(shift+F1) // http://crynut84.tistory.com/34 참조 { SW.Stop(); SW.Reset(); #region /*when user makes first click event after magnification is generated*/ if (flag_mag_start) { flag_mag_start = false; return((IntPtr)1); } #endregion else { switch (mouseEvent_var) { case (int)mouseEvent.LCLICKED: mouse_event(LEFTUP, 0, 0, 0, 0); break; // return 1: vkCode(up 키) 메세지를 메세지 큐로 전달하지 않음 (=up 키가 작동되지 않음) // return CallNextHookEx(hhook, code, (int)wParam, lParam); : 해당 메세지를 큐로 전달함 case (int)mouseEvent.RCLICKED: mouse_event(RIGHTUP, 0, 0, 0, 0); mouseEvent_var = (int)mouseEvent.LCLICKED; break; case (int)mouseEvent.DOUBLECLICKED: mouse_event(LEFTUP, 0, 0, 0, 0); mouse_event(LEFTDOWN, 0, 0, 0, 0); mouse_event(LEFTUP, 0, 0, 0, 0); mouseEvent_var = (int)mouseEvent.LCLICKED; break; case (int)mouseEvent.DRAGCLICKED: mouseEvent_var = (int)mouseEvent.RELEASED; break; } #region /*magnification closing*/ if (magnifierWindowLens != null) { magnifierWindowLens.Close(); magnifierWindowLens = null; return((IntPtr)1); } else { return((IntPtr)1); } } } return(CallNextHookEx(hhook, code, (int)wParam, lParam)); } #endregion #endregion else { return(CallNextHookEx(hhook, code, (int)wParam, lParam)); } }