void setMouse(intf x,intf y)
{	if (winVars.factive!=WA_ACTIVE) return;
	if (winVars.isWindowMode)	
		mouse_event( MOUSEEVENTF_ABSOLUTE | MOUSEEVENTF_MOVE, 
				 ((x+winVars.winPosX)*65536+32768)/desktopMetrics->width, ((y+winVars.winPosY)*65536+32768)/desktopMetrics->height,
				 0, GetMessageExtraInfo() );
	else
		mouse_event( MOUSEEVENTF_ABSOLUTE | MOUSEEVENTF_MOVE, 
				 ((x)*65536+32768)/screenWidth, ((y)*65536+32768)/screenHeight,
				 0, GetMessageExtraInfo() );

}
Пример #2
0
/***********************************************************************
 *
 *           OSK_ReleaseKey
 *
 *  Release the key of ID wCommand
 */
BOOL OSK_ReleaseKey(WORD ScanCode)
{
    INPUT Input;
    BOOL bExtendedKey;
    LONG WindowStyle;
    HWND hWndControl;

    /* Is it a 2-states key ? */
    hWndControl = GetDlgItem(Globals.hMainWnd, ScanCode);
    WindowStyle = GetWindowLongW(hWndControl, GWL_STYLE);
    if ((WindowStyle & BS_AUTOCHECKBOX) != BS_AUTOCHECKBOX) return FALSE;

    /* Is the key down ? */
    if (SendMessageW(hWndControl, BM_GETCHECK, 0, 0) != BST_CHECKED) return TRUE;

    /* Extended key ? */
    if (ScanCode & 0x0200)
        bExtendedKey = TRUE;
    else
        bExtendedKey = FALSE;
    ScanCode &= 0xFF;

    /* Release the key */
    Input.type = INPUT_KEYBOARD;
    Input.ki.wVk = 0;
    Input.ki.wScan = ScanCode;
    Input.ki.time = GetTickCount();
    Input.ki.dwExtraInfo = GetMessageExtraInfo();
    Input.ki.dwFlags = KEYEVENTF_SCANCODE | KEYEVENTF_KEYUP;
    if (bExtendedKey) Input.ki.dwFlags |= KEYEVENTF_EXTENDEDKEY;
    SendInput(1, &Input, sizeof(Input));

    return TRUE;
}
Пример #3
0
BOOL WINAPI pausePlayMediaEnumProc(HWND hwnd, LPARAM lParam)
{	
	if (hwnd == msgWindow ||
		!IsWindowVisible(hwnd))
	{
		return true;
	}

	int length = GetWindowTextLength(hwnd) + 1;
	char* titleBuff = new char[length];
	GetWindowText(hwnd, titleBuff, length);

	UINT count = sizeof(mediaCommands) / sizeof(mediaCommands[0]);
	for (UINT i = 0; i < count; i++)
	{
		if (strstr(titleBuff, mediaCommands[i].title) > 0)
		{
			mediaEnumInput* input = (mediaEnumInput*)lParam;
			input->hasChangedVolume = true;

			if (input->simulatePause && mediaCommands[i].button == NULL)
			{
				KEYBDINPUT kb = {};
				kb.wVk = VK_MEDIA_PLAY_PAUSE;
				kb.dwExtraInfo = GetMessageExtraInfo();

				INPUT input = {};
				input.type = INPUT_KEYBOARD;
				input.ki = kb;

				SendInput(1, &input, sizeof(INPUT));
				
				kb.dwFlags = KEYEVENTF_KEYUP;
				SendInput(1, &input, sizeof(INPUT));
			}
			else
			{
				LONG windowStyles = GetWindowLong(hwnd, GWL_EXSTYLE);
				LONG windowStyleNoActive = windowStyles | WS_EX_NOACTIVATE;

				SetWindowLong(hwnd, GWL_EXSTYLE, windowStyleNoActive);
				SendMessage(hwnd, WM_ACTIVATE, WA_ACTIVE, 0);
				SendMessage(hwnd, WM_KEYDOWN, mediaCommands[i].button, 0);
				SendMessage(hwnd, WM_KEYUP, mediaCommands[i].button, 0);
				SendMessage(hwnd, WM_ACTIVATE, WA_INACTIVE, 0);
				SetWindowLong(hwnd, GWL_EXSTYLE, windowStyles);
			}

			break;
		}
	}

	delete[] titleBuff;
	return true;
}
Пример #4
0
//向全局发送单一键击
void SendKey(WORD key)
{
	KEYBDINPUT kbi = { 0 };
	kbi.wVk = key;
	kbi.dwExtraInfo = (ULONG_PTR)GetMessageExtraInfo();

	INPUT input = { 0 };
	input.type = INPUT_KEYBOARD;
	input.ki = kbi;

	SendInput(1, &input, sizeof(INPUT));
}
Пример #5
0
BOOL CHooks::IsRemoteInputMessage()
{
	if (gEnableRemoteInput)
	{
		return FALSE;
	}

	if (gIsInRemoteDesktop) //Ô¶³Ì×ÀÃæ
	{
		return TRUE;
	}

	LONG_PTR ExtraInfo = GetMessageExtraInfo();

	return ExtraInfo == 2011;
}
Пример #6
0
/*===================================================================
函数名称 :  sendkeyString
功能描述 :  模拟键盘发送字符串

返回值: 返回值:BOOL类型
_TRUE表示成功,_FALSE表示失败

参数:
名称        类型             描述
-----------------------------------------------
list       MyDataList *   传进来键盘按下的字符串
ret        _variant_t *      接收返回值传出去

修改历史 :
修改者   日期           描述
邓媛元   2010-07-18      
邓媛元   2010-07-20     检测 
====================================================================*/
bool  MyKeyboardNamespace::sendkeyString(wchar_t *strs,DWORD delays)
{
	int length = wcslen(strs);
	for (int i = 0; i < length; ++i)
	{
		INPUT   keyin;
		keyin.type=INPUT_KEYBOARD;
		keyin.ki.wVk=0;
		keyin.ki.wScan=strs[i];
		keyin.ki.time=100;
		keyin.ki.dwFlags=KEYEVENTF_UNICODE;
		keyin.ki.dwExtraInfo=GetMessageExtraInfo();
		::SendInput(1,  &keyin, sizeof(INPUT));
		Sleep(delays);
	}
	return true;
}
Пример #7
0
void hapticAPI::mouseRenderLeftButton(){
	INPUT input[1];
	ZeroMemory(input, 1*sizeof(INPUT));

	input[0].type = INPUT_MOUSE;
	input[0].mi.dwExtraInfo = GetMessageExtraInfo();
	input[0].mi.dwFlags = MOUSEEVENTF_LEFTDOWN | MOUSEEVENTF_LEFTUP;

	SendInput(1, input, sizeof(INPUT));

	/*
	typedef struct tagINPUT {
		DWORD type;		= INPUT_MOUSE:		The event is a mouse event. Use the mi structure of the union.
						= INPUT_KEYBOARD:	The event is a keyboard event. Use the ki structure of the union.
						= INPUT_HARDWARE:	The event is a hardware event. Use the hi structure of the union

		union {
			MOUSEINPUT    mouse;
			KEYBDINPUT    ki;
			HARDWAREINPUT hi;
		};
	} INPUT
					typedef struct tagMOUSEINPUT {
								  LONG      dx;
								  LONG      dy;
								  DWORD     mouseData;
								  DWORD     dwFlags;
								  DWORD     time;
								  ULONG_PTR dwExtraInfo;
					} MOUSEINPUT


					INPUT input

					//input.type = INPUT_MOUSE;
					//input.mi.dx = ;  //coordinate assolute o incrementali rispetto all'ultima posizione, depending on dwFlags
					//input.mi.dy = ;  //coordinate assolute o incrementali rispetto all'ultima posizione, depending on dwFlags
					//input.mi.dwFlags = MOUSEEVENTF_MOVE | MOUSEEVENTF_ABSOLUTE | MOUSEEVENTF_LEFTUP;
					//input.mi.dwExtraInfo = GetMessageExtraInfo();

	*/
}
Пример #8
0
LRESULT CALLBACK InputModule::keybd_proc(int nCode, WPARAM wParam, LPARAM lParam)
{
  InputModule* m = (InputModule*) GetMessageExtraInfo();
  if (nCode < 0 || m == NULL)
    CallNextHookEx(0, nCode, wParam, lParam);
  KBDLLHOOKSTRUCT* kbd = (KBDLLHOOKSTRUCT*) lParam;
  int code = 0;
  if ((kbd->flags & LLKHF_INJECTED) == 0)
  {
    if (wParam == WM_KEYUP)
      m->keyTable[kbd->vkCode] = 0x00;
    else
      m->keyTable[kbd->vkCode] = 0x80;
    if (wParam == WM_KEYUP || wParam == WM_SYSKEYUP)
      code = (kbd->vkCode | InputList::curmod() | mUP);
    else if (wParam == WM_KEYDOWN || wParam == WM_SYSKEYDOWN)
      code = (kbd->vkCode | InputList::curmod());
    uint32 msg = IM_ONHOOK;
    if (m->binds[code])
    {
      if ((code & mALT) && !(code & mCTRL))
        InputList::unalt();
      PostThreadMessage(m->tid, IM_HOTKEY, code, 0);
      msg = IM_ONHOOK_HK;
    }
    else
      code = 0;
    PostThreadMessage(m->tid, msg, wParam, kbd->vkCode);
  }
  if (code == 0)
  {
    kbd->flags &= ~LLKHF_INJECTED;
    return CallNextHookEx(0, nCode, wParam, lParam);
  }
  return TRUE;
}
Пример #9
0
LRESULT CALLBACK InputModule::mouse_proc(int nCode, WPARAM wParam, LPARAM lParam)
{
  InputModule* m = (InputModule*) GetMessageExtraInfo();
  if (nCode < 0 || m == NULL)
    return CallNextHookEx(0, nCode, wParam, lParam);
  MSLLHOOKSTRUCT* ms = (MSLLHOOKSTRUCT*) lParam;
  int code = 0;
  if ((ms->flags & LLMHF_INJECTED) == 0)
  {
    switch (wParam)
    {
    case WM_LBUTTONDOWN:
      code = VK_LBUTTON | InputList::curmod();
      break;
    case WM_LBUTTONUP:
      code = VK_LBUTTON | InputList::curmod() | mUP;
      break;
    case WM_RBUTTONDOWN:
      code = VK_RBUTTON | InputList::curmod();
      break;
    case WM_RBUTTONUP:
      code = VK_RBUTTON | InputList::curmod() | mUP;
      break;
    case WM_MBUTTONDOWN:
      code = VK_MBUTTON | InputList::curmod();
      break;
    case WM_MBUTTONUP:
      code = VK_MBUTTON | InputList::curmod() | mUP;
      break;
    case WM_XBUTTONDOWN:
      code = (HIWORD(ms->mouseData) == XBUTTON2 ? VK_XBUTTON2 : VK_XBUTTON1) | InputList::curmod();
      break;
    case WM_XBUTTONUP:
      code = (HIWORD(ms->mouseData) == XBUTTON2 ? VK_XBUTTON2 : VK_XBUTTON1) | InputList::curmod() | mUP;
      break;
    case WM_MOUSEWHEEL:
      code = (GET_WHEEL_DELTA_WPARAM(ms->mouseData) > 0 ? VK_WHEELUP : VK_WHEELDOWN) | InputList::curmod();
      break;
    case WM_MOUSEHWHEEL:
      code = (GET_WHEEL_DELTA_WPARAM(ms->mouseData) > 0 ? VK_WHEELRIGHT : VK_WHEELLEFT) | InputList::curmod();
      break;
    }
    uint32 msg = IM_ONHOOK;
    if (m->binds[code])
    {
      if ((code & mALT) && !(code & mCTRL))
        InputList::unalt();
      PostThreadMessage(m->tid, IM_HOTKEY, code, 0);
      msg = IM_ONHOOK_HK;
    }
    else
      code = 0;
    PostThreadMessage(m->tid, msg, wParam, (wParam == WM_MOUSEMOVE ?
      MAKELONG(ms->pt.x, ms->pt.y) : ms->mouseData));
  }
  if (code == 0)
  {
    ms->flags &= ~LLMHF_INJECTED;
    return CallNextHookEx(0, nCode, wParam, lParam);
  }
  return TRUE;
}
Пример #10
0
void iupdrvSendKey(int key, int press)
{
  unsigned int keyval, state;
  INPUT input[2];
  LPARAM extra_info;
  WORD state_scan = 0, key_scan;
  ZeroMemory(input, 2*sizeof(INPUT));

  iupdrvKeyEncode(key, &keyval, &state);
  if (!keyval)
    return;

  extra_info = GetMessageExtraInfo();
  if (state)
    state_scan = (WORD)MapVirtualKey(state, MAPVK_VK_TO_VSC);
  key_scan = (WORD)MapVirtualKey(keyval, MAPVK_VK_TO_VSC);

  if (press & 0x01)
  {
    if (state)
    {
      /* modifier first */
      input[0].type = INPUT_KEYBOARD;
      input[0].ki.wVk = (WORD)state;
      input[0].ki.wScan = state_scan;
      input[0].ki.dwExtraInfo = extra_info;

      /* key second */
      input[1].type = INPUT_KEYBOARD;
      input[1].ki.wVk = (WORD)keyval;
      input[1].ki.wScan = key_scan;
      input[1].ki.dwExtraInfo = extra_info;

      SendInput(2, input, sizeof(INPUT));
    }
    else
    {
      input[0].type = INPUT_KEYBOARD;
      input[0].ki.wVk = (WORD)keyval;
      input[0].ki.wScan = key_scan;
      input[0].ki.dwExtraInfo = extra_info;

      SendInput(1, input, sizeof(INPUT));
    }
  }

  if (press & 0x02)
  {
    if (state)
    {
      /* key first */
      input[0].type = INPUT_KEYBOARD;
      input[0].ki.dwFlags = KEYEVENTF_KEYUP;
      input[0].ki.wVk = (WORD)keyval;
      input[0].ki.wScan = key_scan;
      input[0].ki.dwExtraInfo = extra_info;

      /* modifier second */
      input[1].type = INPUT_KEYBOARD;
      input[1].ki.dwFlags = KEYEVENTF_KEYUP;
      input[1].ki.wVk = (WORD)state;
      input[1].ki.wScan = state_scan;
      input[1].ki.dwExtraInfo = extra_info;

      SendInput(2, input, sizeof(INPUT));
    }
    else
    {
      input[0].type = INPUT_KEYBOARD;
      input[0].ki.dwFlags = KEYEVENTF_KEYUP;
      input[0].ki.wVk = (WORD)keyval;
      input[0].ki.wScan = key_scan;
      input[0].ki.dwExtraInfo = extra_info;

      SendInput(1, input, sizeof(INPUT));
    }
  }
}
Пример #11
0
void iupdrvSendMouse(int x, int y, int bt, int status)
{
  INPUT input;
  ZeroMemory(&input, sizeof(INPUT));

  input.type = INPUT_MOUSE;
  input.mi.dx = x;
  input.mi.dy = y;
  input.mi.dwFlags = MOUSEEVENTF_ABSOLUTE;
  input.mi.dwExtraInfo = GetMessageExtraInfo();

  /* PROBLEMS:
    Menu items are not activated. Although submenus open, menu items even in the menu bar are not activated.
    Inside the FileOpen dialog, clicks in the folder navigation list are not correctly interpreted.
  */

  if (status==-1)
  {
    input.mi.dwFlags |= MOUSEEVENTF_MOVE;
  }
  else
  {
    input.mi.dwFlags |= winGetButtonStatus(bt, status);

    switch(bt)
    {
    case 'W':
      input.mi.mouseData = status*120;
      input.mi.dwFlags |= MOUSEEVENTF_WHEEL;
      break;
    case IUP_BUTTON4:
      input.mi.mouseData = XBUTTON1;
      break;
    case IUP_BUTTON5:
      input.mi.mouseData = XBUTTON2;
      break;
    }
  }

  if (status == 2)  /* double click */
  {
    SendInput(1, &input, sizeof(INPUT));  /* press */

    input.mi.dwFlags = MOUSEEVENTF_ABSOLUTE;
    input.mi.dwFlags |= winGetButtonStatus(bt, 0);
    SendInput(1, &input, sizeof(INPUT));  /* release */

    input.mi.dwFlags = MOUSEEVENTF_ABSOLUTE;
    input.mi.dwFlags |= winGetButtonStatus(bt, 1);
    SendInput(1, &input, sizeof(INPUT));  /* press */

    input.mi.dwFlags = MOUSEEVENTF_ABSOLUTE;
    input.mi.dwFlags |= winGetButtonStatus(bt, 0);
    SendInput(1, &input, sizeof(INPUT));  /* release */
  }
  else
    SendInput(1, &input, sizeof(INPUT));

  /* always update cursor */
  /* in Windows, update cursor after mouse messages */
  /* this will NOT generate and extra motion event */
  iupdrvWarpPointer(x, y);
}
	/* Static Functions */
	LRESULT CALLBACK WMTouchEventSource::wmTouchProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
	{
		assert(prevWndProc);
		assert(instance);

		if(msg == WM_TABLET_QUERYSYSTEMGESTURESTATUS)
		{
			return	(TABLET_DISABLE_PRESSANDHOLD		|
					TABLET_DISABLE_PENTAPFEEDBACK		|
					TABLET_DISABLE_PENBARRELFEEDBACK	|
					TABLET_DISABLE_TOUCHUIFORCEON		|
					TABLET_DISABLE_TOUCHUIFORCEOFF		|
					TABLET_DISABLE_TOUCHSWITCH			|
					TABLET_DISABLE_FLICKS);

		}
		else if(msg == WM_TOUCH)
		{
			// WM_TOUCH message can contain several messages from different contacts
            // packed together.
            // Message parameters need to be decoded:
            unsigned int numInputs = (unsigned int) wParam; // Number of actual per-contact messages
            TOUCHINPUT* ti = new TOUCHINPUT[numInputs];		// Allocate the storage for the parameters of the per-contact messages
            if (ti == NULL)
            {
                return 0;
            }

            // Unpack message parameters into the array of TOUCHINPUT structures, each
            // representing a message for one single contact.
            if (GetTouchInputInfo((HTOUCHINPUT)lParam, numInputs, ti, sizeof(TOUCHINPUT)))
            {
                // For each contact, dispatch the message to the appropriate message
                // handler.
                for (unsigned int i = 0; i < numInputs; ++i)
                {
                    if (ti[i].dwFlags & TOUCHEVENTF_DOWN)
                    {
						instance->touchDown(&ti[i]);
                    }
                    else if (ti[i].dwFlags & TOUCHEVENTF_MOVE)
                    {
						instance->touchMove(&ti[i]);
                    }
                    else if (ti[i].dwFlags & TOUCHEVENTF_UP)
                    {
						instance->touchUp(&ti[i]);
                    }
                }
            }
            CloseTouchInputHandle((HTOUCHINPUT)lParam);
            delete [] ti;
		}
		else if((msg == WM_LBUTTONDOWN) && ((GetMessageExtraInfo() & MOUSEEVENTF_FROMTOUCH) == MOUSEEVENTF_FROMTOUCH))
		{
			// ignore clicks caused by touches
			return 0;
		}
		else
		{
			LRESULT result = CallWindowProc(prevWndProc, hWnd, msg, wParam, lParam);
			return result;
		}

		return NULL;
	}
Пример #13
0
	LRESULT CALLBACK DisplayProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) {
		static bool firstErase = true;

		switch (message) {
		case WM_ACTIVATE:
			if (wParam == WA_ACTIVE || wParam == WA_CLICKACTIVE) {
				g_activeWindow = WINDOW_MAINWINDOW;
			}
			break;

		case WM_SIZE:
			break;

		case WM_SETFOCUS:
			break;

		case WM_ERASEBKGND:
			if (firstErase) {
				firstErase = false;
				// Paint black on first erase while OpenGL stuff is loading
				return DefWindowProc(hWnd, message, wParam, lParam);
			}
			// Then never erase, let the OpenGL drawing take care of everything.
			return 1;

		// Poor man's touch - mouse input. We send the data  asynchronous touch events for minimal latency.
		case WM_LBUTTONDOWN:
			if (!touchHandler.hasTouch() ||
				(GetMessageExtraInfo() & MOUSEEVENTF_MASK_PLUS_PENTOUCH) != MOUSEEVENTF_FROMTOUCH_NOPEN)
			{
				// Hack: Take the opportunity to show the cursor.
				mouseButtonDown = true;

				float x = GET_X_LPARAM(lParam) * g_dpi_scale_x;
				float y = GET_Y_LPARAM(lParam) * g_dpi_scale_y;
				WindowsRawInput::SetMousePos(x, y);

				TouchInput touch;
				touch.id = 0;
				touch.flags = TOUCH_DOWN;
				touch.x = x;
				touch.y = y;
				NativeTouch(touch);
				SetCapture(hWnd);

				// Simulate doubleclick, doesn't work with RawInput enabled
				static double lastMouseDown;
				double now = real_time_now();
				if ((now - lastMouseDown) < 0.001 * GetDoubleClickTime()) {
					if (!g_Config.bShowTouchControls && !g_Config.bMouseControl && GetUIState() == UISTATE_INGAME && g_Config.bFullscreenOnDoubleclick) {
						SendToggleFullscreen(!g_Config.bFullScreen);
					}
					lastMouseDown = 0.0;
				} else {
					lastMouseDown = real_time_now();
				}
			}
			break;

		case WM_MOUSEMOVE:
			if (!touchHandler.hasTouch() ||
				(GetMessageExtraInfo() & MOUSEEVENTF_MASK_PLUS_PENTOUCH) != MOUSEEVENTF_FROMTOUCH_NOPEN)
			{
				// Hack: Take the opportunity to show the cursor.
				mouseButtonDown = (wParam & MK_LBUTTON) != 0;
				int cursorX = GET_X_LPARAM(lParam);
				int cursorY = GET_Y_LPARAM(lParam);
				if (abs(cursorX - prevCursorX) > 1 || abs(cursorY - prevCursorY) > 1) {
					hideCursor = false;
					SetTimer(hwndMain, TIMER_CURSORMOVEUPDATE, CURSORUPDATE_MOVE_TIMESPAN_MS, 0);
				}
				prevCursorX = cursorX;
				prevCursorY = cursorY;

				float x = (float)cursorX * g_dpi_scale_x;
				float y = (float)cursorY * g_dpi_scale_y;
				WindowsRawInput::SetMousePos(x, y);

				if (wParam & MK_LBUTTON) {
					TouchInput touch;
					touch.id = 0;
					touch.flags = TOUCH_MOVE;
					touch.x = x;
					touch.y = y;
					NativeTouch(touch);
				}
			}
			break;

		case WM_LBUTTONUP:
			if (!touchHandler.hasTouch() ||
				(GetMessageExtraInfo() & MOUSEEVENTF_MASK_PLUS_PENTOUCH) != MOUSEEVENTF_FROMTOUCH_NOPEN)
			{
				// Hack: Take the opportunity to hide the cursor.
				mouseButtonDown = false;

				float x = (float)GET_X_LPARAM(lParam) * g_dpi_scale_x;
				float y = (float)GET_Y_LPARAM(lParam) * g_dpi_scale_y;
				WindowsRawInput::SetMousePos(x, y);

				TouchInput touch;
				touch.id = 0;
				touch.flags = TOUCH_UP;
				touch.x = x;
				touch.y = y;
				NativeTouch(touch);
				ReleaseCapture();
			}
			break;

		case WM_TOUCH:
			{
				touchHandler.handleTouchEvent(hWnd, message, wParam, lParam);
				return 0;
			}

		default:
			return DefWindowProc(hWnd, message, wParam, lParam);
		}
		return 0;
	}
Пример #14
0
/* postKeyMessage: post key message */
static void postKeyMessage(const char *args)
{
   int i;
   char *buff, *param1, *param2, *param3, *param4, *param5, *save;
   HWND window;
   unsigned int id = 0;
   INPUT input[8];
   int size;
   bool alt = false, ctrl = false, shift = false;
   LPARAM info;

   buff = MMDAgent_strdup(args);
   param1 = MMDAgent_strtok(buff, "|", &save); /* window name */
   param2 = MMDAgent_strtok(NULL, "|", &save); /* key */
   param3 = MMDAgent_strtok(NULL, "|", &save); /* shift-key */
   param4 = MMDAgent_strtok(NULL, "|", &save); /* control-key */
   param5 = MMDAgent_strtok(NULL, "|", &save); /* alt-key */

   /* check */
   if(buff == NULL || param1 == NULL || param2 == NULL) {
      free(buff);
      return;
   }

   /* get window handle */
   window = FindWindowA(param1, NULL);
   if(window == 0) {
      free(buff);
      return;
   }

   /* get key ID */
   if(MMDAgent_strlen(param2) == 1) {
      id = toupper(param2[0]);
   } else {
      for(i = 0; keys[i].name != NULL; i++) {
         if(MMDAgent_strequal(param2, keys[i].name) == true) {
            id = keys[i].id;
            break;
         }
      }
   }
   if(id == 0) {
      free(buff);
      return;
   }

   /* set forground window */
   SetForegroundWindow(window);

   /* get options */
   shift = MMDAgent_strequal(param3, "ON");
   ctrl = MMDAgent_strequal(param4, "ON");
   alt = MMDAgent_strequal(param5, "ON");

   /* create key message */
   size = 0;
   info = GetMessageExtraInfo();
   if(shift == true && id != VK_SHIFT) {
      input[size].type = INPUT_KEYBOARD;
      input[size].ki.wVk = VK_SHIFT;
      input[size].ki.wScan = MapVirtualKey(VK_SHIFT, 0);
      input[size].ki.dwFlags = 0;
      input[size].ki.time = 0;
      input[size].ki.dwExtraInfo = info;
      size++;
   }
   if(ctrl == true && id != VK_CONTROL) {
      input[size].type = INPUT_KEYBOARD;
      input[size].ki.wVk = VK_CONTROL;
      input[size].ki.wScan = MapVirtualKey(VK_CONTROL, 0);
      input[size].ki.dwFlags = 0;
      input[size].ki.time = 0;
      input[size].ki.dwExtraInfo = info;
      size++;
   }
   if(alt == true && id != VK_MENU) {
      input[size].type = INPUT_KEYBOARD;
      input[size].ki.wVk = VK_MENU;
      input[size].ki.wScan = MapVirtualKey(VK_MENU, 0);
      input[size].ki.dwFlags = 0;
      input[size].ki.time = 0;
      input[size].ki.dwExtraInfo = info;
      size++;
   }
   input[size].type = INPUT_KEYBOARD;
   input[size].ki.wVk = id;
   input[size].ki.wScan = MapVirtualKey(id, 0);
   input[size].ki.dwFlags = 0;
   input[size].ki.time = 0;
   input[size].ki.dwExtraInfo = info;
   size++;
   input[size].type = INPUT_KEYBOARD;
   input[size].ki.wVk = id;
   input[size].ki.wScan = MapVirtualKey(id, 0);
   input[size].ki.dwFlags = KEYEVENTF_KEYUP;
   input[size].ki.time = 0;
   input[size].ki.dwExtraInfo = info;
   size++;
   if(alt == true && id != VK_MENU) {
      input[size].type = INPUT_KEYBOARD;
      input[size].ki.wVk = VK_MENU;
      input[size].ki.wScan = MapVirtualKey(VK_MENU, 0);
      input[size].ki.dwFlags = KEYEVENTF_KEYUP;
      input[size].ki.time = 0;
      input[size].ki.dwExtraInfo = info;
      size++;
   }
   if(ctrl == true && id != VK_CONTROL) {
      input[size].type = INPUT_KEYBOARD;
      input[size].ki.wVk = VK_CONTROL;
      input[size].ki.wScan = MapVirtualKey(VK_CONTROL, 0);
      input[size].ki.dwFlags = KEYEVENTF_KEYUP;
      input[size].ki.time = 0;
      input[size].ki.dwExtraInfo = info;
      size++;
   }
   if(shift == true && id != VK_SHIFT) {
      input[size].type = INPUT_KEYBOARD;
      input[size].ki.wVk = VK_SHIFT;
      input[size].ki.wScan = MapVirtualKey(VK_SHIFT, 0);
      input[size].ki.dwFlags = KEYEVENTF_KEYUP;
      input[size].ki.time = 0;
      input[size].ki.dwExtraInfo = info;
      size++;
   }

   /* send key message */
   SendInput(size, input, sizeof(INPUT));

   free(buff);
}
Пример #15
0
bool QWindowsMouseHandler::translateMouseEvent(QWindow *window, HWND hwnd,
                                               QtWindows::WindowsEventType et,
                                               MSG msg, LRESULT *result)
{
#ifdef Q_COMPILER_CLASS_ENUM
    enum : quint64 { signatureMask = 0xffffff00, miWpSignature = 0xff515700 };
#else
    static const quint64 signatureMask = 0xffffff00;
    static const quint64 miWpSignature = 0xff515700;
#endif // !Q_COMPILER_CLASS_ENUM

    if (et == QtWindows::MouseWheelEvent)
        return translateMouseWheelEvent(window, hwnd, msg, result);

    Qt::MouseEventSource source = Qt::MouseEventNotSynthesized;

    // Check for events synthesized from touch. Lower byte is touch index, 0 means pen.
    static const bool passSynthesizedMouseEvents =
            !(QWindowsIntegration::instance()->options() & QWindowsIntegration::DontPassOsMouseEventsSynthesizedFromTouch);
    // Check for events synthesized from touch. Lower 7 bits are touch/pen index, bit 8 indicates touch.
    // However, when tablet support is active, extraInfo is a packet serial number. This is not a problem
    // since we do not want to ignore mouse events coming from a tablet.
    // See https://msdn.microsoft.com/en-us/library/windows/desktop/ms703320.aspx
    const quint64 extraInfo = quint64(GetMessageExtraInfo());
    if ((extraInfo & signatureMask) == miWpSignature) {
        if (extraInfo & 0x80) { // Bit 7 indicates touch event, else tablet pen.
            source = Qt::MouseEventSynthesizedBySystem;
            if (!passSynthesizedMouseEvents)
                return false;
        }
    }

    const QPoint winEventPosition(GET_X_LPARAM(msg.lParam), GET_Y_LPARAM(msg.lParam));
    if (et & QtWindows::NonClientEventFlag) {
        const QPoint globalPosition = winEventPosition;
        const QPoint clientPosition = QWindowsGeometryHint::mapFromGlobal(hwnd, globalPosition);
        const Qt::MouseButtons buttons = QWindowsMouseHandler::queryMouseButtons();
        QWindowSystemInterface::handleFrameStrutMouseEvent(window, clientPosition,
                                                           globalPosition, buttons,
                                                           QWindowsKeyMapper::queryKeyboardModifiers(),
                                                           source);
        return false; // Allow further event processing (dragging of windows).
    }

    *result = 0;
    if (msg.message == WM_MOUSELEAVE) {
        qCDebug(lcQpaEvents) << "WM_MOUSELEAVE for " << window << " previous window under mouse = " << m_windowUnderMouse << " tracked window =" << m_trackedWindow;

        // When moving out of a window, WM_MOUSEMOVE within the moved-to window is received first,
        // so if m_trackedWindow is not the window here, it means the cursor has left the
        // application.
        if (window == m_trackedWindow) {
            QWindow *leaveTarget = m_windowUnderMouse ? m_windowUnderMouse : m_trackedWindow;
            qCDebug(lcQpaEvents) << "Generating leave event for " << leaveTarget;
            QWindowSystemInterface::handleLeaveEvent(leaveTarget);
            m_trackedWindow = 0;
            m_windowUnderMouse = 0;
        }
        return true;
    }

    QWindowsWindow *platformWindow = static_cast<QWindowsWindow *>(window->handle());
    const Qt::MouseButtons buttons = keyStateToMouseButtons(int(msg.wParam));

    // If the window was recently resized via mouse doubleclick on the frame or title bar,
    // we don't get WM_LBUTTONDOWN or WM_LBUTTONDBLCLK for the second click,
    // but we will get at least one WM_MOUSEMOVE with left button down and the WM_LBUTTONUP,
    // which will result undesired mouse press and release events.
    // To avoid those, we ignore any events with left button down if we didn't
    // get the original WM_LBUTTONDOWN/WM_LBUTTONDBLCLK.
    if (msg.message == WM_LBUTTONDOWN || msg.message == WM_LBUTTONDBLCLK) {
        m_leftButtonDown = true;
    } else {
        const bool actualLeftDown = buttons & Qt::LeftButton;
        if (!m_leftButtonDown && actualLeftDown) {
            // Autocapture the mouse for current window to and ignore further events until release.
            // Capture is necessary so we don't get WM_MOUSELEAVEs to confuse matters.
            // This autocapture is released normally when button is released.
            if (!platformWindow->hasMouseCapture()) {
                platformWindow->applyCursor();
                platformWindow->setMouseGrabEnabled(true);
                platformWindow->setFlag(QWindowsWindow::AutoMouseCapture);
                qCDebug(lcQpaEvents) << "Automatic mouse capture for missing buttondown event" << window;
            }
            m_previousCaptureWindow = window;
            return true;
        } else if (m_leftButtonDown && !actualLeftDown) {
            m_leftButtonDown = false;
        }
    }

    const QPoint globalPosition = QWindowsGeometryHint::mapToGlobal(hwnd, winEventPosition);
    // In this context, neither an invisible nor a transparent window (transparent regarding mouse
    // events, "click-through") can be considered as the window under mouse.
    QWindow *currentWindowUnderMouse = platformWindow->hasMouseCapture() ?
        QWindowsScreen::windowAt(globalPosition, CWP_SKIPINVISIBLE | CWP_SKIPTRANSPARENT) : window;
    while (currentWindowUnderMouse && currentWindowUnderMouse->flags() & Qt::WindowTransparentForInput)
        currentWindowUnderMouse = currentWindowUnderMouse->parent();
    // QTBUG-44332: When Qt is running at low integrity level and
    // a Qt Window is parented on a Window of a higher integrity process
    // using QWindow::fromWinId() (for example, Qt running in a browser plugin)
    // ChildWindowFromPointEx() may not find the Qt window (failing with ERROR_ACCESS_DENIED)
    if (!currentWindowUnderMouse) {
        const QRect clientRect(QPoint(0, 0), window->size());
        if (clientRect.contains(winEventPosition))
            currentWindowUnderMouse = window;
    }

    compressMouseMove(&msg);
    // Qt expects the platform plugin to capture the mouse on
    // any button press until release.
    if (!platformWindow->hasMouseCapture()
        && (msg.message == WM_LBUTTONDOWN || msg.message == WM_MBUTTONDOWN
            || msg.message == WM_RBUTTONDOWN || msg.message == WM_XBUTTONDOWN
            || msg.message == WM_LBUTTONDBLCLK || msg.message == WM_MBUTTONDBLCLK
            || msg.message == WM_RBUTTONDBLCLK || msg.message == WM_XBUTTONDBLCLK)) {
        platformWindow->setMouseGrabEnabled(true);
        platformWindow->setFlag(QWindowsWindow::AutoMouseCapture);
        qCDebug(lcQpaEvents) << "Automatic mouse capture " << window;
        // Implement "Click to focus" for native child windows (unless it is a native widget window).
        if (!window->isTopLevel() && !window->inherits("QWidgetWindow") && QGuiApplication::focusWindow() != window)
            window->requestActivate();
    } else if (platformWindow->hasMouseCapture()
               && platformWindow->testFlag(QWindowsWindow::AutoMouseCapture)
               && (msg.message == WM_LBUTTONUP || msg.message == WM_MBUTTONUP
                   || msg.message == WM_RBUTTONUP || msg.message == WM_XBUTTONUP)
               && !buttons) {
        platformWindow->setMouseGrabEnabled(false);
        qCDebug(lcQpaEvents) << "Releasing automatic mouse capture " << window;
    }

    const bool hasCapture = platformWindow->hasMouseCapture();
    const bool currentNotCapturing = hasCapture && currentWindowUnderMouse != window;
    // Enter new window: track to generate leave event.
    // If there is an active capture, only track if the current window is capturing,
    // so we don't get extra leave when cursor leaves the application.
    if (window != m_trackedWindow && !currentNotCapturing) {
        TRACKMOUSEEVENT tme;
        tme.cbSize = sizeof(TRACKMOUSEEVENT);
        tme.dwFlags = TME_LEAVE;
        tme.hwndTrack = hwnd;
        tme.dwHoverTime = HOVER_DEFAULT; //
        if (!TrackMouseEvent(&tme))
            qWarning("TrackMouseEvent failed.");
        m_trackedWindow =  window;
    }

    // No enter or leave events are sent as long as there is an autocapturing window.
    if (!hasCapture || !platformWindow->testFlag(QWindowsWindow::AutoMouseCapture)) {
        // Leave is needed if:
        // 1) There is no capture and we move from a window to another window.
        //    Note: Leaving the application entirely is handled in WM_MOUSELEAVE case.
        // 2) There is capture and we move out of the capturing window.
        // 3) There is a new capture and we were over another window.
        if ((m_windowUnderMouse && m_windowUnderMouse != currentWindowUnderMouse
                && (!hasCapture || window == m_windowUnderMouse))
            || (hasCapture && m_previousCaptureWindow != window && m_windowUnderMouse
                && m_windowUnderMouse != window)) {
            qCDebug(lcQpaEvents) << "Synthetic leave for " << m_windowUnderMouse;
            QWindowSystemInterface::handleLeaveEvent(m_windowUnderMouse);
            if (currentNotCapturing) {
                // Clear tracking if capturing and current window is not the capturing window
                // to avoid leave when mouse actually leaves the application.
                m_trackedWindow = 0;
                // We are not officially in any window, but we need to set some cursor to clear
                // whatever cursor the left window had, so apply the cursor of the capture window.
                platformWindow->applyCursor();
            }
        }
        // Enter is needed if:
        // 1) There is no capture and we move to a new window.
        // 2) There is capture and we move into the capturing window.
        // 3) The capture just ended and we are over non-capturing window.
        if ((currentWindowUnderMouse && m_windowUnderMouse != currentWindowUnderMouse
                && (!hasCapture || currentWindowUnderMouse == window))
            || (m_previousCaptureWindow && window != m_previousCaptureWindow && currentWindowUnderMouse
                && currentWindowUnderMouse != m_previousCaptureWindow)) {
            QPoint localPosition;
            qCDebug(lcQpaEvents) << "Entering " << currentWindowUnderMouse;
            if (QWindowsWindow *wumPlatformWindow = QWindowsWindow::windowsWindowOf(currentWindowUnderMouse)) {
                localPosition = wumPlatformWindow->mapFromGlobal(globalPosition);
                wumPlatformWindow->applyCursor();
            }
            QWindowSystemInterface::handleEnterEvent(currentWindowUnderMouse, localPosition, globalPosition);
        }
        // We need to track m_windowUnderMouse separately from m_trackedWindow, as
        // Windows mouse tracking will not trigger WM_MOUSELEAVE for leaving window when
        // mouse capture is set.
        m_windowUnderMouse = currentWindowUnderMouse;
    }

    QWindowSystemInterface::handleMouseEvent(window, winEventPosition, globalPosition, buttons,
                                             QWindowsKeyMapper::queryKeyboardModifiers(),
                                             source);
    m_previousCaptureWindow = hasCapture ? window : 0;
    // QTBUG-48117, force synchronous handling for the extra buttons so that WM_APPCOMMAND
    // is sent for unhandled WM_XBUTTONDOWN.
    return (msg.message != WM_XBUTTONUP && msg.message != WM_XBUTTONDOWN && msg.message != WM_XBUTTONDBLCLK)
        || QWindowSystemInterface::flushWindowSystemEvents();
}
Пример #16
0
	LRESULT CALLBACK DisplayProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) {
		// Only apply a factor > 1 in windowed mode.
		int factor = !IsZoomed(GetHWND()) && !g_Config.bFullScreen && IsWindowSmall() ? 2 : 1;
		static bool firstErase = true;

		switch (message) {
		case WM_ACTIVATE:
			if (wParam == WA_ACTIVE || wParam == WA_CLICKACTIVE) {
				g_activeWindow = WINDOW_MAINWINDOW;
			}
			break;

		case WM_SIZE:
			break;

		case WM_SETFOCUS:
			break;

		case WM_ERASEBKGND:
			if (firstErase) {
				firstErase = false;
				// Paint black on first erase while OpenGL stuff is loading
				return DefWindowProc(hWnd, message, wParam, lParam);
			}
			// Then never erase, let the OpenGL drawing take care of everything.
			return 1;

		// Poor man's touch - mouse input. We send the data both as an input_state pointer,
		// and as asynchronous touch events for minimal latency.
		case WM_LBUTTONDOWN:
			if (!touchHandler.hasTouch() ||
				(GetMessageExtraInfo() & MOUSEEVENTF_MASK_PLUS_PENTOUCH) != MOUSEEVENTF_FROMTOUCH_NOPEN)
			{
				// Hack: Take the opportunity to show the cursor.
				mouseButtonDown = true;
				{
					lock_guard guard(input_state.lock);
					input_state.mouse_valid = true;
					input_state.pointer_down[0] = true;

					input_state.pointer_x[0] = GET_X_LPARAM(lParam) * factor; 
					input_state.pointer_y[0] = GET_Y_LPARAM(lParam) * factor;
				}

				TouchInput touch;
				touch.id = 0;
				touch.flags = TOUCH_DOWN;
				touch.x = input_state.pointer_x[0];
				touch.y = input_state.pointer_y[0];
				NativeTouch(touch);
				SetCapture(hWnd);

				// Simulate doubleclick, doesn't work with RawInput enabled
				static double lastMouseDown;
				double now = real_time_now();
				if ((now - lastMouseDown) < 0.001 * GetDoubleClickTime()) {
					if (!g_Config.bShowTouchControls && GetUIState() == UISTATE_INGAME) {
						PostMessage(hwndMain, WM_USER_TOGGLE_FULLSCREEN, 0, 0);
					}
					lastMouseDown = 0.0;
				} else {
					lastMouseDown = real_time_now();
				}
			}
			break;

		case WM_MOUSEMOVE:
			if (!touchHandler.hasTouch() ||
				(GetMessageExtraInfo() & MOUSEEVENTF_MASK_PLUS_PENTOUCH) != MOUSEEVENTF_FROMTOUCH_NOPEN)
			{
				// Hack: Take the opportunity to show the cursor.
				mouseButtonDown = (wParam & MK_LBUTTON) != 0;
				int cursorX = GET_X_LPARAM(lParam);
				int cursorY = GET_Y_LPARAM(lParam);
				if (abs(cursorX - prevCursorX) > 1 || abs(cursorY - prevCursorY) > 1) {
					hideCursor = false;
					SetTimer(hwndMain, TIMER_CURSORMOVEUPDATE, CURSORUPDATE_MOVE_TIMESPAN_MS, 0);
				}
				prevCursorX = cursorX;
				prevCursorY = cursorY;

				{
					lock_guard guard(input_state.lock);
					input_state.pointer_x[0] = GET_X_LPARAM(lParam) * factor; 
					input_state.pointer_y[0] = GET_Y_LPARAM(lParam) * factor;
				}

				if (wParam & MK_LBUTTON) {
					TouchInput touch;
					touch.id = 0;
					touch.flags = TOUCH_MOVE;
					touch.x = input_state.pointer_x[0];
					touch.y = input_state.pointer_y[0];
					NativeTouch(touch);
				}
			}
			break;

		case WM_LBUTTONUP:
			if (!touchHandler.hasTouch() ||
				(GetMessageExtraInfo() & MOUSEEVENTF_MASK_PLUS_PENTOUCH) != MOUSEEVENTF_FROMTOUCH_NOPEN)
			{
				// Hack: Take the opportunity to hide the cursor.
				mouseButtonDown = false;
				{
					lock_guard guard(input_state.lock);
					input_state.pointer_down[0] = false;
					input_state.pointer_x[0] = GET_X_LPARAM(lParam) * factor; 
					input_state.pointer_y[0] = GET_Y_LPARAM(lParam) * factor;
				}
				TouchInput touch;
				touch.id = 0;
				touch.flags = TOUCH_UP;
				touch.x = input_state.pointer_x[0];
				touch.y = input_state.pointer_y[0];
				NativeTouch(touch);
				ReleaseCapture();
			}
			break;

		case WM_TOUCH:
			{
				touchHandler.handleTouchEvent(hWnd, message, wParam, lParam);
				return 0;
			}

		default:
			return DefWindowProc(hWnd, message, wParam, lParam);
		}
		return 0;
	}
Пример #17
0
/***********************************************************************
 *
 *           OSK_DlgCommand
 *
 *  All handling of dialog command
 */
BOOL OSK_DlgCommand(WPARAM wCommand, HWND hWndControl)
{
    WORD ScanCode;
    INPUT Input;
    BOOL bExtendedKey;
    BOOL bKeyDown;
    BOOL bKeyUp;
    LONG WindowStyle;

    /* FIXME: To be deleted when ReactOS will support WS_EX_NOACTIVATE */
    if (Globals.hActiveWnd)
    {
        MSG msg;

        SetForegroundWindow(Globals.hActiveWnd);
        while (PeekMessageW(&msg, 0, 0, 0, PM_REMOVE))
        {
            TranslateMessage(&msg);
            DispatchMessageW(&msg);
        }
    }

    /* KeyDown and/or KeyUp ? */
    WindowStyle = GetWindowLongW(hWndControl, GWL_STYLE);
    if ((WindowStyle & BS_AUTOCHECKBOX) == BS_AUTOCHECKBOX)
    {
        /* 2-states key like Shift, Alt, Ctrl, ... */
        if (SendMessageW(hWndControl, BM_GETCHECK, 0, 0) == BST_CHECKED)
        {
            bKeyDown = TRUE;
            bKeyUp = FALSE;
        }
        else
        {
            bKeyDown = FALSE;
            bKeyUp = TRUE;
        }
    }
    else
    {
        /* Other key */
        bKeyDown = TRUE;
        bKeyUp = TRUE;
    }

    /* Extended key ? */
    ScanCode = wCommand;
    if (ScanCode & 0x0200)
        bExtendedKey = TRUE;
    else
        bExtendedKey = FALSE;
    ScanCode &= 0xFF;

    /* Press and release the key */
    if (bKeyDown)
    {
        Input.type = INPUT_KEYBOARD;
        Input.ki.wVk = 0;
        Input.ki.wScan = ScanCode;
        Input.ki.time = GetTickCount();
        Input.ki.dwExtraInfo = GetMessageExtraInfo();
        Input.ki.dwFlags = KEYEVENTF_SCANCODE;
        if (bExtendedKey) Input.ki.dwFlags |= KEYEVENTF_EXTENDEDKEY;
        SendInput(1, &Input, sizeof(Input));
    }

    if (bKeyUp)
    {
        Input.type = INPUT_KEYBOARD;
        Input.ki.wVk = 0;
        Input.ki.wScan = ScanCode;
        Input.ki.time = GetTickCount();
        Input.ki.dwExtraInfo = GetMessageExtraInfo();
        Input.ki.dwFlags = KEYEVENTF_SCANCODE | KEYEVENTF_KEYUP;
        if (bExtendedKey) Input.ki.dwFlags |= KEYEVENTF_EXTENDEDKEY;
        SendInput(1, &Input, sizeof(Input));
    }

    return TRUE;
}
Пример #18
0
//Args	-	wVk (WORD) : Input to process : NOT NULL
//			lParam (LPARAM) : lParm passed from hooks
//return -	true : Input was eatten.
//			false : Input was not processed.
bool ProcessInput(WORD wVk, LPARAM lParam)
{
	try {

		WORD scancode = (WORD)(lParam >> 16);
		DWORD dwExtraInfo = GetMessageExtraInfo();
		// If VK_BACK and there is any DontEatBackspace, subtract the DontEatBackspace count from lParam
		if (wVk == VK_BACK && DontEatBackspace > 0 && ((BYTE)scancode == 0xff))
		{
			DontEatBackspace -= lParam & 0xFF;
			if (DontEatBackspace < 0) // lParam is larger then DontEatBackspace
			{ // Eat
				InternalEditor.Delete (0 - DontEatBackspace); // And delete additional sendBackspace (Hack for internal editor)
				DontEatBackspace = 0;
			}
			return false;
		}

		// Do not need to do anything, just pass it
		if (wVk == VK_CONTROL || wVk == VK_MENU || wVk == VK_SHIFT)
			return false;

		BYTE GlobalKeyStates[256];
		GetKeyboardState(GlobalKeyStates); // Get States

		// Store mod keys to use it later
		mksOldState.CTRL = GlobalKeyStates[VK_CONTROL] & 0x80;
		mksOldState.ALT = GlobalKeyStates[VK_MENU] & 0x80;
		mksOldState.SHIFT = GlobalKeyStates[VK_SHIFT] & 0x80;
		mksOldState.CAPS = GlobalKeyStates[VK_CAPITAL] & 0x81;

		Debug(L"CTRL = %x ALT = %x\n", mksOldState.CTRL, mksOldState.ALT);

		wchar_t wcInput = wVk;
		UINT usVk;

		if (usVk = TranslateToUnicode((WORD*)&wcInput, GlobalKeyStates)) // Get Ascii Value
		{ // If there is any ascii value
			if (matchRules(wcInput, usVk, GlobalKeyStates, true )) {// Match for the input
				// Found matched
				return true; // Eaten
			}
			else if (wVk == VK_BACK) {
				// If VK_BACK
				return false;
				//InternalEditor.Delete(lParam & 0xFF); // Delete from internal editor
			}
			else if (klf.layout.eat==true && //eat unused key
				mksOldState.CTRL==false && mksOldState.ALT==false &&
				wcInput > 0x20 && wcInput < 0x7F) {
					InternalEditor.undoEnd();
					return true;
			}
			else if (mksOldState.CTRL==false && mksOldState.ALT==false) {
				InternalEditor.AddInput(wcInput); // Not matched? Just store the input
				return false;
			}
		} else {
			if (wVk != 0xe7) {// unicode input
				if (matchRules(NULL, wVk, GlobalKeyStates, true )) {// Match for the input
					// Found matched
					return true; // Eaten
				}
			}
		}

		//If only one of these two keys are pressed
		if (mksOldState.CTRL ^ mksOldState.ALT){
			Debug(L"(isCTRL ^ isALT)\n");
			InternalEditor.Reset();// restart the internal editor's buffer
			return false;
		}
		
	} catch (...) {
		Debug(L"Caught exception!\n");
	}
	return false;
}
Пример #19
0
bool QWindowsMouseHandler::translateMouseEvent(QWindow *window, HWND hwnd,
                                               QtWindows::WindowsEventType et,
                                               MSG msg, LRESULT *result)
{
#ifdef Q_COMPILER_CLASS_ENUM
    enum : quint64 { signatureMask = 0xffffff00, miWpSignature = 0xff515700 };
#else
    static const quint64 signatureMask = 0xffffff00;
    static const quint64 miWpSignature = 0xff515700;
#endif // !Q_COMPILER_CLASS_ENUM

    if (et == QtWindows::MouseWheelEvent)
        return translateMouseWheelEvent(window, hwnd, msg, result);

#ifndef Q_OS_WINCE
    // Check for events synthesized from touch. Lower byte is touch index, 0 means pen.
    const quint64 extraInfo = GetMessageExtraInfo();
    const bool fromTouch = (extraInfo & signatureMask) == miWpSignature && (extraInfo & 0xff);
    if (fromTouch)
        return false;
#endif // !Q_OS_WINCE

    const QPoint winEventPosition(GET_X_LPARAM(msg.lParam), GET_Y_LPARAM(msg.lParam));
    if (et & QtWindows::NonClientEventFlag) {
        const QPoint globalPosition = winEventPosition;
        const QPoint clientPosition = QWindowsGeometryHint::mapFromGlobal(hwnd, globalPosition);
        const Qt::MouseButtons buttons = QWindowsMouseHandler::queryMouseButtons();
        QWindowSystemInterface::handleFrameStrutMouseEvent(window, clientPosition,
                                                           globalPosition, buttons,
                                                           QWindowsKeyMapper::queryKeyboardModifiers());
        return false; // Allow further event processing (dragging of windows).
    }

    *result = 0;
    if (msg.message == WM_MOUSELEAVE) {
        if (QWindowsContext::verboseEvents)
            qDebug() << "WM_MOUSELEAVE for " << window << " previous window under mouse = " << m_windowUnderMouse << " tracked window =" << m_trackedWindow;

        // When moving out of a window, WM_MOUSEMOVE within the moved-to window is received first,
        // so if m_trackedWindow is not the window here, it means the cursor has left the
        // application.
        if (window == m_trackedWindow) {
            QWindow *leaveTarget = m_windowUnderMouse ? m_windowUnderMouse : m_trackedWindow;
            if (QWindowsContext::verboseEvents)
                qDebug() << "Generating leave event for " << leaveTarget;
            QWindowSystemInterface::handleLeaveEvent(leaveTarget);
            m_trackedWindow = 0;
            m_windowUnderMouse = 0;
        }
        return true;
    }

    QWindowsWindow *platformWindow = static_cast<QWindowsWindow *>(window->handle());
    const Qt::MouseButtons buttons = keyStateToMouseButtons((int)msg.wParam);

    // If the window was recently resized via mouse doubleclick on the frame or title bar,
    // we don't get WM_LBUTTONDOWN or WM_LBUTTONDBLCLK for the second click,
    // but we will get at least one WM_MOUSEMOVE with left button down and the WM_LBUTTONUP,
    // which will result undesired mouse press and release events.
    // To avoid those, we ignore any events with left button down if we didn't
    // get the original WM_LBUTTONDOWN/WM_LBUTTONDBLCLK.
    if (msg.message == WM_LBUTTONDOWN || msg.message == WM_LBUTTONDBLCLK) {
        m_leftButtonDown = true;
    } else {
        const bool actualLeftDown = buttons & Qt::LeftButton;
        if (!m_leftButtonDown && actualLeftDown) {
            // Autocapture the mouse for current window to and ignore further events until release.
            // Capture is necessary so we don't get WM_MOUSELEAVEs to confuse matters.
            // This autocapture is released normally when button is released.
            if (!platformWindow->hasMouseCapture()) {
                QWindowsWindow::baseWindowOf(window)->applyCursor();
                platformWindow->setMouseGrabEnabled(true);
                platformWindow->setFlag(QWindowsWindow::AutoMouseCapture);
                if (QWindowsContext::verboseEvents)
                    qDebug() << "Automatic mouse capture for missing buttondown event" << window;
            }
            m_previousCaptureWindow = window;
            return true;
        } else if (m_leftButtonDown && !actualLeftDown) {
            m_leftButtonDown = false;
        }
    }

    const QPoint globalPosition = QWindowsGeometryHint::mapToGlobal(hwnd, winEventPosition);
    // In this context, neither an invisible nor a transparent window (transparent regarding mouse
    // events, "click-through") can be considered as the window under mouse.
    QWindow *currentWindowUnderMouse = platformWindow->hasMouseCapture() ?
        QWindowsScreen::windowAt(globalPosition, CWP_SKIPINVISIBLE | CWP_SKIPTRANSPARENT) : window;

    compressMouseMove(&msg);
    // Qt expects the platform plugin to capture the mouse on
    // any button press until release.
    if (!platformWindow->hasMouseCapture()
        && (msg.message == WM_LBUTTONDOWN || msg.message == WM_MBUTTONDOWN
            || msg.message == WM_RBUTTONDOWN || msg.message == WM_XBUTTONDOWN
            || msg.message == WM_LBUTTONDBLCLK || msg.message == WM_MBUTTONDBLCLK
            || msg.message == WM_RBUTTONDBLCLK || msg.message == WM_XBUTTONDBLCLK)) {
        platformWindow->setMouseGrabEnabled(true);
        platformWindow->setFlag(QWindowsWindow::AutoMouseCapture);
        if (QWindowsContext::verboseEvents)
            qDebug() << "Automatic mouse capture " << window;
        // Implement "Click to focus" for native child windows (unless it is a native widget window).
        if (!window->isTopLevel() && !window->inherits("QWidgetWindow") && QGuiApplication::focusWindow() != window)
            window->requestActivate();
    } else if (platformWindow->hasMouseCapture()
               && platformWindow->testFlag(QWindowsWindow::AutoMouseCapture)
               && (msg.message == WM_LBUTTONUP || msg.message == WM_MBUTTONUP
                   || msg.message == WM_RBUTTONUP || msg.message == WM_XBUTTONUP)
               && !buttons) {
        platformWindow->setMouseGrabEnabled(false);
        if (QWindowsContext::verboseEvents)
            qDebug() << "Releasing automatic mouse capture " << window;
    }

    const bool hasCapture = platformWindow->hasMouseCapture();
    const bool currentNotCapturing = hasCapture && currentWindowUnderMouse != window;
#ifndef Q_OS_WINCE
    // Enter new window: track to generate leave event.
    // If there is an active capture, only track if the current window is capturing,
    // so we don't get extra leave when cursor leaves the application.
    if (window != m_trackedWindow && !currentNotCapturing) {
        TRACKMOUSEEVENT tme;
        tme.cbSize = sizeof(TRACKMOUSEEVENT);
        tme.dwFlags = TME_LEAVE;
        tme.hwndTrack = hwnd;
        tme.dwHoverTime = HOVER_DEFAULT; //
        if (!TrackMouseEvent(&tme))
            qWarning("TrackMouseEvent failed.");
        m_trackedWindow =  window;
    }
#endif // !Q_OS_WINCE

    // No enter or leave events are sent as long as there is an autocapturing window.
    if (!hasCapture || !platformWindow->testFlag(QWindowsWindow::AutoMouseCapture)) {
        // Leave is needed if:
        // 1) There is no capture and we move from a window to another window.
        //    Note: Leaving the application entirely is handled in WM_MOUSELEAVE case.
        // 2) There is capture and we move out of the capturing window.
        // 3) There is a new capture and we were over another window.
        if ((m_windowUnderMouse && m_windowUnderMouse != currentWindowUnderMouse
                && (!hasCapture || window == m_windowUnderMouse))
            || (hasCapture && m_previousCaptureWindow != window && m_windowUnderMouse
                && m_windowUnderMouse != window)) {
            if (QWindowsContext::verboseEvents)
                qDebug() << "Synthetic leave for " << m_windowUnderMouse;
            QWindowSystemInterface::handleLeaveEvent(m_windowUnderMouse);
            if (currentNotCapturing) {
                // Clear tracking if capturing and current window is not the capturing window
                // to avoid leave when mouse actually leaves the application.
                m_trackedWindow = 0;
                // We are not officially in any window, but we need to set some cursor to clear
                // whatever cursor the left window had, so apply the cursor of the capture window.
                QWindowsWindow::baseWindowOf(window)->applyCursor();
            }
        }
        // Enter is needed if:
        // 1) There is no capture and we move to a new window.
        // 2) There is capture and we move into the capturing window.
        // 3) The capture just ended and we are over non-capturing window.
        if ((currentWindowUnderMouse && m_windowUnderMouse != currentWindowUnderMouse
                && (!hasCapture || currentWindowUnderMouse == window))
            || (m_previousCaptureWindow && window != m_previousCaptureWindow && currentWindowUnderMouse
                && currentWindowUnderMouse != m_previousCaptureWindow)) {
            if (QWindowsContext::verboseEvents)
                qDebug() << "Entering " << currentWindowUnderMouse;
            QWindowsWindow::baseWindowOf(currentWindowUnderMouse)->applyCursor();
            QWindowSystemInterface::handleEnterEvent(currentWindowUnderMouse,
                                                     currentWindowUnderMouse->mapFromGlobal(globalPosition),
                                                     globalPosition);
        }
        // We need to track m_windowUnderMouse separately from m_trackedWindow, as
        // Windows mouse tracking will not trigger WM_MOUSELEAVE for leaving window when
        // mouse capture is set.
        m_windowUnderMouse = currentWindowUnderMouse;
    }

    QWindowSystemInterface::handleMouseEvent(window, winEventPosition, globalPosition, buttons,
                                             QWindowsKeyMapper::queryKeyboardModifiers());
    m_previousCaptureWindow = hasCapture ? window : 0;
    return true;
}