Пример #1
0
LRESULT CALLBACK RawInputProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
	switch(uMsg) {
	case WM_CREATE:
		if(eatenWnd == NULL) RegisterRaw(hWnd, 0);
		break;
	case WM_INPUT:
		{
		//if(skipInput) return;
		PRAWINPUT pRawInput;
		UINT      bufferSize=0;
		GetRawInputData((HRAWINPUT)lParam, RID_INPUT, NULL, &bufferSize, sizeof(RAWINPUTHEADER));
		pRawInput = (PRAWINPUT)malloc(bufferSize);
		if(!pRawInput)
			break;
		GetRawInputData((HRAWINPUT)lParam, RID_INPUT, pRawInput, &bufferSize, sizeof(RAWINPUTHEADER));
		ParseRawInput(pRawInput);
		free(pRawInput);
		break;
		}
	case WM_DESTROY:
		if(eatenWnd==NULL) RegisterRaw(hWnd, RIDEV_REMOVE);
		UninitWindow();
		break;
	}
	
	if(eatenWndProc)
		return CallWindowProc(eatenWndProc, hWnd, uMsg, wParam, lParam);
	//else
	//	return DefWindowProc(hWnd, uMsg, wParam, lParam);
	return 0;
}
Пример #2
0
int InitWindow(HWND hWnd)
{
#if 1
	if (!InitHid())
		return 0;

	RegisterRaw(hWnd, 0);
	hHook = SetWindowsHookEx(WH_GETMESSAGE, HookProc, hInst, 0);
	//hHookKB = SetWindowsHookEx(WH_KEYBOARD_LL, KBHookProc, hInst, 0);
	int err = GetLastError();
#else
	eatenWnd = hWnd;
	eatenWndProc = (WNDPROC) SetWindowLongPtr(hWnd, GWLP_WNDPROC, (LONG_PTR)RawInputProc);
	RegisterRaw(hWnd, 0);
#endif
	return 1;
}
Пример #3
0
int Initialize(void *ptr)
{
	HWND hWnd = reinterpret_cast<HWND> (ptr);
	if (!InitHid())
		return 0;

#if 0
	if (!RegisterRaw(hWnd))
		return 0;
	hHook = SetWindowsHookEx(WH_GETMESSAGE, HookProc, hInst, 0);
	//hHookWnd = SetWindowsHookEx(WH_CALLWNDPROC, HookWndProc, hInst, 0);
	//hHookKB = SetWindowsHookEx(WH_KEYBOARD_LL, KBHookProc, hInst, 0);
	int err = GetLastError();
#else
	eatenWnd = hWnd;
	eatenWndProc = (WNDPROC) SetWindowLongPtr(hWnd, GWLP_WNDPROC, (LONG_PTR)RawInputProc);
	RegisterRaw(hWnd);
#endif
	return 1;
}
Пример #4
0
static LRESULT CALLBACK RawInputProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
	MyWndProc(hWnd, uMsg, wParam, lParam);

	switch(uMsg) {
	case WM_CREATE:
		if (eatenWnd == nullptr)
			RegisterRaw(hWnd);
		break;
	case WM_INPUT:
		{
		//if(skipInput) return;
		PRAWINPUT pRawInput;
		UINT      bufferSize=0;
		GetRawInputData((HRAWINPUT)lParam, RID_INPUT, NULL, &bufferSize, sizeof(RAWINPUTHEADER));
		pRawInput = (PRAWINPUT)malloc(bufferSize);
		if(!pRawInput)
			break;
		if (GetRawInputData((HRAWINPUT)lParam, RID_INPUT, pRawInput, &bufferSize, sizeof(RAWINPUTHEADER)) > 0) {
			for (auto cb : callbacks)
				cb->ParseRawInput(pRawInput);
		}
		free(pRawInput);
		break;
		}
	case WM_ACTIVATE:
		OSDebugOut(TEXT("******      WM_ACTIVATE        ******\n"));
		break;
	case WM_DESTROY:
		if (eatenWnd == nullptr)
			RegisterRaw(nullptr);
		Uninitialize();
		break;
	}

	if(eatenWndProc)
		return CallWindowProc(eatenWndProc, hWnd, uMsg, wParam, lParam);
	//else
	//	return DefWindowProc(hWnd, uMsg, wParam, lParam);
	return 0;
}
Пример #5
0
void Uninitialize()
{
	if(hHook)
	{
		UnhookWindowsHookEx(hHook);
		//UnhookWindowsHookEx(hHookKB);
		hHook = 0;
	}
	if(eatenWnd)
		RegisterRaw(nullptr);
	if(eatenWnd && eatenWndProc)
		SetWindowLongPtr(eatenWnd, GWLP_WNDPROC, (LONG_PTR)eatenWndProc);
	eatenWndProc = nullptr;
	eatenWnd = nullptr;
}
Пример #6
0
void UninitWindow()
{
	if(hHook)
	{
		UnhookWindowsHookEx(hHook);
		//UnhookWindowsHookEx(hHookKB);
		hHook = 0;
	}
	if(eatenWnd != NULL)
	{
		RegisterRaw(eatenWnd, RIDEV_REMOVE);
		SetWindowLongPtr(eatenWnd, GWLP_WNDPROC, (LONG_PTR)eatenWndProc);
		eatenWndProc = NULL;
		eatenWnd = NULL;
	}
}