/* Register window to receive RawInput messages */ BOOL register_rawidev(char *log_file_path, HWND h_wnd){ RAWINPUTDEVICE raw_idev; /* * Setup RawInput shizznet * http://msdn.microsoft.com/en-us/library/windows/desktop/ms645546(v=vs.85).aspx * http://msdn.microsoft.com/en-us/library/windows/desktop/ms645565(v=vs.85).aspx * http://msdn.microsoft.com/en-us/library/windows/desktop/ms645562(v=vs.85).aspx */ raw_idev.usUsagePage = 0x01; raw_idev.usUsage = 0x06; raw_idev.dwFlags = RIDEV_INPUTSINK | RIDEV_NOLEGACY; raw_idev.hwndTarget = h_wnd; if (RegisterRawInputDevices(&raw_idev, 1, sizeof(raw_idev)) == FALSE) return FALSE; /* Open log file for output */ h_logfile = CreateFile( log_file_path, GENERIC_WRITE, FILE_SHARE_READ, NULL, OPEN_ALWAYS, LOGFILEATTR, NULL); if(h_logfile == INVALID_HANDLE_VALUE) return FALSE; SetFilePointer(h_logfile, 0, NULL, FILE_END); return TRUE; }
Input::Input() { auto hInst = GetModuleHandle(NULL); register_input_window_class(hInst); _input_window = CreateWindow(_class_name, TEXT("RawInputWindow"), WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, hInst, NULL); if (_input_window == NULL) { std::cout << "Failed to create input window!" << std::endl; } SetWindowLongPtr(_input_window, GWLP_USERDATA, (LONG_PTR)this); ShowWindow(_input_window, SW_HIDE); UpdateWindow(_input_window); enumerate_devices(); RAWINPUTDEVICE Rid[2]; Rid[0].usUsagePage = 0x01; //HID mouse Rid[0].usUsage = 0x02; Rid[0].dwFlags = RIDEV_INPUTSINK; Rid[0].hwndTarget = _input_window; Rid[1].usUsagePage = 0x01; //HID keyboard Rid[1].usUsage = 0x06; Rid[1].dwFlags = RIDEV_INPUTSINK; Rid[1].hwndTarget = _input_window; if (RegisterRawInputDevices(Rid, 2, sizeof(Rid[0])) == FALSE) { std::cout << "Failed to register raw input devices!" << std::endl; } }
void CloseRawInputProxyWnd( HANDLE hHandle ) { if ( hHandle != NULL ) { RAWINPUTDEVICE rid[3]={0}; UINT num=3; rid[0].usUsagePage = 0xFFBC; // adds HID remote control rid[0].usUsage = 0x88; rid[0].dwFlags = RIDEV_REMOVE; rid[0].hwndTarget = 0; rid[1].usUsagePage = 0x0C; // adds HID remote control rid[1].usUsage = 0x01; rid[1].dwFlags = RIDEV_REMOVE; rid[1].hwndTarget = 0; rid[2].usUsagePage = 0x0C; // adds HID remote control rid[2].usUsage = 0x80; rid[2].dwFlags = RIDEV_REMOVE; rid[2].hwndTarget = 0; RegisterRawInputDevices(rid, 3, sizeof(RAWINPUTDEVICE) ); SendMessage((HWND)hHandle, WM_DESTROY, NULL, NULL ); #ifdef FUJITSU_BUILD if (hEvtKiller) CloseHandle(hEvtKiller); #endif } }
//============================================================================= // Initialize mouse and controller input // Set capture=true to capture mouse // Throws GameError //============================================================================= void Input::initialize(HWND hwnd, bool capture) { try{ mouseCaptured = capture; // register high-definition mouse Rid[0].usUsagePage = HID_USAGE_PAGE_GENERIC; Rid[0].usUsage = HID_USAGE_GENERIC_MOUSE; Rid[0].dwFlags = RIDEV_INPUTSINK; Rid[0].hwndTarget = hwnd; RegisterRawInputDevices(Rid, 1, sizeof(Rid[0])); if(mouseCaptured) { SetCapture(hwnd); // capture mouse } // Clear controllers state ZeroMemory( controllers, sizeof(ControllerState) * MAX_CONTROLLERS ); checkControllers(); // check for connected controllers window = hwnd; } catch(...) { //"Error initializing input system" } }
void createWindow(SystemEventHandler* handler) { g_platform_data.m_handler = handler; HINSTANCE hInst = GetModuleHandle(NULL); WNDCLASSEX wnd; memset(&wnd, 0, sizeof(wnd)); wnd.cbSize = sizeof(wnd); wnd.style = CS_HREDRAW | CS_VREDRAW; wnd.lpfnWndProc = msgProc; wnd.hInstance = hInst; wnd.hIcon = LoadIcon(NULL, IDI_APPLICATION); wnd.hCursor = LoadCursor(NULL, IDC_ARROW); wnd.lpszClassName = "lmxa"; wnd.hIconSm = LoadIcon(NULL, IDI_APPLICATION); RegisterClassExA(&wnd); g_platform_data.m_hwnd = CreateWindowA( "lmxa", "lmxa", WS_OVERLAPPEDWINDOW | WS_VISIBLE, 0, 0, 800, 600, NULL, NULL, hInst, 0); SetWindowTextA(g_platform_data.m_hwnd, "Lumix Studio"); RAWINPUTDEVICE Rid; Rid.usUsagePage = 0x01; Rid.usUsage = 0x02; Rid.dwFlags = 0; Rid.hwndTarget = 0; RegisterRawInputDevices(&Rid, 1, sizeof(Rid)); timeBeginPeriod(1); trackMouse(); Lumix::Renderer::setInitData(g_platform_data.m_hwnd); ImGui::GetIO().ImeWindowHandle = g_platform_data.m_hwnd; }
static void initRawInput() { #ifdef WITH_INPUT_NDOF #define DEVICE_COUNT 2 #else #define DEVICE_COUNT 1 #endif RAWINPUTDEVICE devices[DEVICE_COUNT]; memset(devices, 0, DEVICE_COUNT * sizeof(RAWINPUTDEVICE)); // Initiates WM_INPUT messages from keyboard // That way GHOST can retrieve true keys devices[0].usUsagePage = 0x01; devices[0].usUsage = 0x06; /* http://msdn.microsoft.com/en-us/windows/hardware/gg487473.aspx */ #ifdef WITH_INPUT_NDOF // multi-axis mouse (SpaceNavigator, etc.) devices[1].usUsagePage = 0x01; devices[1].usUsage = 0x08; #endif if (RegisterRawInputDevices(devices, DEVICE_COUNT, sizeof(RAWINPUTDEVICE))) ; // yay! else printf("could not register for RawInput: %d\n", (int)GetLastError()); #undef DEVICE_COUNT }
qboolean IN_ShutdownRawMouse(void) { RAWINPUTDEVICE dev = { 1, // usUsagePage - generic desktop controls 2, // usUsage - mouse RIDEV_REMOVE, // dwFlags NULL // hwndTarget }; if (!RegisterRawInputDevices(&dev, 1, sizeof(dev))) { Com_Printf("Mouse release failed. (0x%lx)\n", GetLastError()); return qfalse; } mouseRaw = qfalse; Com_DPrintf("Released raw input mouse.\n"); if (SDLWindowProc) { SDL_SysWMinfo wmInfo; SDL_VERSION(&wmInfo.version); SDL_GetWMInfo(&wmInfo); SetWindowLongPtr(wmInfo.window, GWLP_WNDPROC, (LONG_PTR)SDLWindowProc); SDLWindowProc = NULL; } return qtrue; }
void GameConsole::displayChat(bool console) { capsLockToggled = GetKeyState(VK_CAPITAL) & 1; if (console) { if (selectedQueue != &consoleQueue) { lastChatQueue = selectedQueue; } selectedQueue = &consoleQueue; showConsole = true; } else { selectedQueue = lastChatQueue; showChat = true; } selectedQueue->startIndexForScrolling = 0; // Disables game keyboard input and enables our keyboard hook RAWINPUTDEVICE Rid; Rid.usUsagePage = 0x01; Rid.usUsage = 0x06; Rid.dwFlags = RIDEV_NOLEGACY; // adds HID keyboard and also ignores legacy keyboard messages Rid.hwndTarget = 0; if (!RegisterRawInputDevices(&Rid, 1, sizeof(Rid))) { consoleQueue.pushLineFromGameToUI("Registering keyboard failed"); } }
void Input::InitializeWindow() { // make invisible window for receiving raw input messages HINSTANCE instance = GetModuleHandle(NULL); WNDCLASSEX classEx = {}; classEx.cbSize = sizeof classEx; classEx.lpfnWndProc = WindowProc; classEx.hInstance = instance; classEx.lpszClassName = L"MeteorInputWindowClass"; if(RegisterClassEx(&classEx) == 0) { LOG_ISSUE("RegisterClassEx failed!"); return; } // create the actual window window = CreateWindowEx(WS_EX_APPWINDOW, classEx.lpszClassName, NULL, NULL, 0, 0, 0, 0, NULL, NULL, instance, NULL); if(window == NULL) { LOG_ISSUE("CreateWindowEx failed!"); return; } // set up notification for detecting gamepads DEV_BROADCAST_DEVICEINTERFACE filter = {}; filter.dbcc_size = sizeof filter; filter.dbcc_devicetype = DBT_DEVTYP_DEVICEINTERFACE; filter.dbcc_classguid = GUID_DEVINTERFACE_HID; deviceNotification = RegisterDeviceNotification(window, &filter, DEVICE_NOTIFY_WINDOW_HANDLE); if(deviceNotification == NULL) { LOG_INFO("Registering device notification for detecting gamepads failed!"); } // set up Raw Input for mouse and keyboard controls { RAWINPUTDEVICE devices[2]; devices[0].usUsagePage = HID_USAGE_PAGE_GENERIC; devices[0].usUsage = HID_USAGE_GENERIC_MOUSE; devices[0].dwFlags = RIDEV_NOLEGACY | RIDEV_CAPTUREMOUSE; devices[0].hwndTarget = window; devices[1].usUsagePage = HID_USAGE_PAGE_GENERIC; devices[1].usUsage = HID_USAGE_GENERIC_KEYBOARD; devices[1].dwFlags = RIDEV_NOLEGACY | RIDEV_NOHOTKEYS; devices[1].hwndTarget = window; BOOL registered = RegisterRawInputDevices(devices, ARRAYSIZE(devices), sizeof(RAWINPUTDEVICE)); if(registered == FALSE) { LOG_INFO("Registering keyboard and/or mouse as Raw Input devices failed!"); } } }
qboolean IN_InitRawMouse(void) { // http://www.usb.org/developers/devclass_docs/Hut1_12.pdf if (!SDLWindowProc) { SDL_SysWMinfo wmInfo; SDL_VERSION(&wmInfo.version); SDL_GetWMInfo(&wmInfo); SDLWindowProc = (WNDPROC)GetWindowLongPtr(wmInfo.window, GWLP_WNDPROC); SetWindowLongPtr(wmInfo.window, GWLP_WNDPROC, (LONG_PTR)RawWndProc); } { RAWINPUTDEVICE dev = { 1, // usUsagePage - generic desktop controls 2, // usUsage - mouse 0, // dwFlags 0 // hwndTarget }; if (!RegisterRawInputDevices(&dev, 1, sizeof(dev))) { Com_Printf("Raw input registration failed. (0x%lx)\n", GetLastError()); return qfalse; } } Com_DPrintf("Registered for raw input.\n"); mouseRaw = qtrue; return qtrue; }
void D3DApp::initInputDevice(void) { RAWINPUTDEVICE rawInputDevice[1]; rawInputDevice[0].usUsagePage = ((USHORT) 0x01); rawInputDevice[0].usUsage = ((USHORT) 0x02); rawInputDevice[0].dwFlags = RIDEV_INPUTSINK; rawInputDevice[0].hwndTarget = m_hWnd; RegisterRawInputDevices(rawInputDevice, 1, sizeof(rawInputDevice[0])); }
bool nxRawInputDevice::RegisterMouseHandler(HWND hEvent,bool bCaptureMouse) { RAWINPUTDEVICE rid; rid.usUsagePage = 0x01; rid.usUsage = 0x02; rid.dwFlags = RIDEV_INPUTSINK | RIDEV_NOLEGACY | (bCaptureMouse?RIDEV_CAPTUREMOUSE:0); rid.hwndTarget = hEvent; return (RegisterRawInputDevices(&rid,1,sizeof(RAWINPUTDEVICE))); }
bool nxRawInputDevice::RemoveMouseHandler(HWND hEvent) { RAWINPUTDEVICE rid; rid.usUsagePage = 0x01; rid.usUsage = 0x02; rid.dwFlags = RIDEV_REMOVE; rid.hwndTarget = hEvent; return (RegisterRawInputDevices(&rid,1,sizeof(RAWINPUTDEVICE))); }
static BOOL UnregisterForRawInputs() { RAWINPUTDEVICE rawInputDevice; rawInputDevice.dwFlags = RIDEV_REMOVE; rawInputDevice.hwndTarget = NULL; rawInputDevice.usUsagePage = DEVICE_USAGE_PAGE; rawInputDevice.usUsage = DEVICE_USAGE; return RegisterRawInputDevices(&rawInputDevice, 1, sizeof(rawInputDevice)); }
StaticWindowManager() { if (!gWindowClassInitialized) { HINSTANCE instance = (HINSTANCE)GetModuleHandle(NULL); memset(&gWindowClass, 0, sizeof(gWindowClass)); gWindowClass.style = 0; gWindowClass.lpfnWndProc = WinProc; gWindowClass.hInstance = instance; gWindowClass.hIcon = LoadIcon(NULL, IDI_APPLICATION); gWindowClass.hCursor = LoadCursor(NULL, IDC_ARROW); gWindowClass.lpszClassName = CONFETTI_WINDOW_CLASS; gAppRunning = RegisterClassW(&gWindowClass) != 0; if (!gAppRunning) { //Get the error message, if any. DWORD errorMessageID = ::GetLastError(); if (errorMessageID != ERROR_CLASS_ALREADY_EXISTS) { LPSTR messageBuffer = nullptr; size_t size = FormatMessageA(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, NULL, errorMessageID, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPSTR)&messageBuffer, 0, NULL); String message(messageBuffer, size); ErrorMsg(message.c_str()); return; } else { gAppRunning = true; gWindowClassInitialized = gAppRunning; } } RAWINPUTDEVICE Rid[2]; Rid[0].usUsagePage = 0x01; Rid[0].usUsage = 0x02; Rid[0].dwFlags = 0; // adds HID mouse and also ignores legacy mouse messages Rid[0].hwndTarget = 0; Rid[1].usUsagePage = 0x01; Rid[1].usUsage = 0x06; Rid[1].dwFlags = 0; // adds HID keyboard and also ignores legacy keyboard messages Rid[1].hwndTarget = 0; if (RegisterRawInputDevices(Rid, 2, sizeof(Rid[0])) == FALSE) { LOGERRORF("Failed to register raw input devices"); //registration failed. Call GetLastError for the cause of the error } } collectMonitorInfo(); }
bool nxRawInputDevice::RegisterKeyboardHandler(HWND hEvent) { RAWINPUTDEVICE rid; rid.usUsagePage = 0x01; rid.usUsage = 0x06; rid.dwFlags = RIDEV_INPUTSINK | RIDEV_APPKEYS | RIDEV_NOLEGACY; rid.hwndTarget = hEvent; return (RegisterRawInputDevices(&rid,1,sizeof(RAWINPUTDEVICE))); }
LRESULT CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) { switch (msg) { case WM_INPUT: OnRawInput( GET_RAWINPUT_CODE_WPARAM(wParam) == RIM_INPUT, (HRAWINPUT)lParam ); return(DefWindowProc(hWnd, msg, wParam, lParam)); case WM_MOUSEWHEEL: OutputDebugString(_T("WM_MOUSEWHEEL\n")); TCHAR buffer[1024]; memset(buffer, NULL, 1024); _stprintf_s(buffer, 1024, _T(" wheel delta=%d\n"), GET_WHEEL_DELTA_WPARAM(wParam)); OutputDebugString(buffer); break; // Windows XP までは tilt は専用ドライバによってWM_HSCROLLを発行している場合が多いらしい case WM_HSCROLL: OutputDebugString(_T("WM_HSCROLL\n")); break; // Windows Vista からは tilt は WM_MOUSEHWHEEL で検出できるらしい case WM_MOUSEHWHEEL: OutputDebugString(_T("WM_MOUSEHWHEEL\n")); break; case WM_CREATE: device.usUsagePage = 0x01; device.usUsage = 0x02; device.dwFlags = 0; device.hwndTarget = 0; RegisterRawInputDevices(&device, 1, sizeof device); break; case WM_DESTROY: device.usUsagePage = 0x01; device.usUsage = 0x02; device.dwFlags = RIDEV_REMOVE; device.hwndTarget = 0; RegisterRawInputDevices(&device, 1, sizeof device); PostQuitMessage(0); break; default: return(DefWindowProc(hWnd, msg, wParam, lParam)); } return (0L); }
void win_mouse_close(void) { RAWINPUTDEVICE ridev; ridev.dwFlags = RIDEV_REMOVE; ridev.hwndTarget = NULL; ridev.usUsagePage = 0x01; ridev.usUsage = 0x02; RegisterRawInputDevices(&ridev, 1, sizeof(ridev)); }
SWL_API enum swl_result swl_platform_allocate(const char *title, unsigned int width, unsigned int height, swl_window_t *window, swl_display_t *display) { WNDCLASS swc; ATOM register_class; RECT rect; HDC hdc; DWORD style = WS_CAPTION | WS_VISIBLE | WS_SYSMENU; if(swl.resizable) style |= WS_SIZEBOX; swc.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC; swc.lpfnWndProc = wnd_proc; swc.cbClsExtra = 0; swc.cbWndExtra = 0; swc.hInstance = 0; swc.hIcon = 0; swc.hCursor = LoadCursor(NULL, IDC_ARROW); swc.lpszMenuName = 0; swc.hbrBackground = 0; swc.lpszClassName = "RenderFrame"; register_class = RegisterClass(&swc); if (!register_class) return SWLR_ERROR_BACKEND_WINAPI_REGISTER_CLASS; SetRect(&rect, 0, 0, width, height); AdjustWindowRectEx(&rect, style, false, 0); window_handle = CreateWindow("RenderFrame", title, style, CW_USEDEFAULT, CW_USEDEFAULT, rect.right - rect.left, rect.bottom - rect.top, 0, 0, 0, 0); if(window_handle == 0) return SWLR_ERROR_BACKEND_WINAPI_HANDLE; hdc = GetDC(window_handle); if (!hdc) return SWLR_ERROR_BACKEND_WINAPI_DEVICE; *display = hdc; *window = window_handle; RAWINPUTDEVICE mouse; mouse.usUsagePage = 1; mouse.usUsage = 2; mouse.dwFlags = 0; mouse.hwndTarget = window_handle; if(RegisterRawInputDevices(&mouse, 1, sizeof(mouse)) == FALSE) return SWLR_ERROR_BACKEND_WINAPI_RAW_INPUT; return SWLR_OK; }
//============================================================================= // Initialize mouse //============================================================================= HRESULT Input::Initialize( HWND hwnd ) { // Register HD mouse m_Rid[0].usUsagePage = HID_USAGE_PAGE_GENERIC; m_Rid[0].usUsage = HID_USAGE_GENERIC_MOUSE; m_Rid[0].dwFlags = RIDEV_INPUTSINK; m_Rid[0].hwndTarget = hwnd; RegisterRawInputDevices( m_Rid, 1, sizeof(m_Rid[0])); return S_OK; }
static BOOL register_raw_mouse( DWORD flags ) { RAWINPUTDEVICE rid; memset( &rid, 0, sizeof( rid ) ); rid.usUsagePage = 0x01; rid.usUsage = 0x02; rid.dwFlags = flags; rid.hwndTarget = win.wnd; return RegisterRawInputDevices( &rid, 1, sizeof( rid ) ); }
void CMainWnd::InitWindow() { try { WindowImplBase::InitWindow(); pCloseBtn = static_cast<CButtonUI*>(m_PaintManager.FindControl(_T("SysCloseBtn"))); pCloseBtn->OnNotify += MakeDelegate(this, &CMainWnd::OnCloseBtnClick, _T("click")); pMsgLabel = static_cast<CLabelUI*>(m_PaintManager.FindControl(_T("msg"))); HMODULE htmp = LoadLibraryA("User32.dll"); if (htmp) { RegisterRawInputDevices = (PRegisterRawInputDevices)GetProcAddress(htmp, "RegisterRawInputDevices"); if (!RegisterRawInputDevices) { MessageBoxA(NULL, "获取RegisterRawInputDevices函数地址失败", "Error", MB_OK); return; } } if (htmp) { GetRawInputData = (PGetRawInputData)GetProcAddress(htmp, "GetRawInputData"); if (!GetRawInputData) { MessageBoxA(NULL, "获取GetRawInputData函数地址失败", "Error", MB_OK); return; } } RAWINPUTDEVICE rid; rid.dwFlags = RIDEV_INPUTSINK; rid.usUsagePage = 0x01; rid.usUsage = 0x06; rid.hwndTarget = this->GetHWND(); //注册原始输入设备 RegisterRawInputDevices(&rid, 1, sizeof(RAWINPUTDEVICE)); hFile = CreateFileA(".\\ZSKLog.log", GENERIC_WRITE, FILE_SHARE_READ, NULL, OPEN_ALWAYS, NULL, NULL); if (hFile == INVALID_HANDLE_VALUE) { MessageBoxA(this->GetHWND(), "创建记录文件失败", "Error", MB_OK); return; } pMsgLabel->SetText(_T("系统初始化完成,择善NB!")); } catch (...) { throw "CMainWnd::Init"; } }
Keyboard::Keyboard(HWND &hwnd) { //Initialise the arrays to false! ZeroMemory(keyStates, KEYBOARD_MAX * sizeof(bool)); ZeroMemory(holdStates, KEYBOARD_MAX * sizeof(bool)); //Tedious windows RAW input stuff rid.usUsagePage = HID_USAGE_PAGE_GENERIC; //The keyboard isn't anything fancy rid.usUsage = HID_USAGE_GENERIC_KEYBOARD; //but it's definitely a keyboard! rid.dwFlags = RIDEV_INPUTSINK; //Yes, we want to always receive RAW input... rid.hwndTarget = hwnd; //Windows OS window handle RegisterRawInputDevices(&rid, 1, sizeof(rid)); //We just want one keyboard, please! }
/* * thanks to this article http://www.rohitab.com/discuss/topic/35415-c-getrawinputdata-keylogger/ */ LRESULT CALLBACK raw_input_device_handler(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) { UINT dwSize; RAWINPUTDEVICE ridMouse; RAWINPUT *buffer; switch(msg) { case WM_CREATE: // Register a raw input devices to capture input ridMouse.usUsagePage = 0x01; ridMouse.usUsage = 0x02; ridMouse.dwFlags = RIDEV_INPUTSINK; ridMouse.hwndTarget = hwnd; if(!RegisterRawInputDevices(&ridMouse, 1, sizeof(RAWINPUTDEVICE))) { LOG_FATAL("Registering mouse raw input device failed!"); return -1; } case WM_INPUT: // request size of the raw input buffer to dwSize GetRawInputData((HRAWINPUT)lParam, RID_INPUT, NULL, &dwSize, sizeof(RAWINPUTHEADER)); // allocate buffer for input data buffer = (RAWINPUT*)HeapAlloc(GetProcessHeap(), 0, dwSize); if(GetRawInputData((HRAWINPUT)lParam, RID_INPUT, buffer, &dwSize, sizeof(RAWINPUTHEADER))) { if (buffer->header.dwType == RIM_TYPEMOUSE) { is_input_blocked = do_handle_mouse( buffer->data.mouse.lLastX, buffer->data.mouse.lLastY, buffer->data.mouse.usButtonFlags, buffer->data.mouse.usButtonData); } } // free the buffer HeapFree(GetProcessHeap(), 0, buffer); break; case WM_DESTROY: PostQuitMessage(0); break; default: return DefWindowProc(hwnd, msg, wParam, lParam); } return 0; }
void fs_ml_init_raw_input() { fs_log("fs_ml_init_raw_input\n"); g_debug_keys = getenv("FS_DEBUG_INPUT") && \ getenv("FS_DEBUG_INPUT")[0] == '1'; //list_input_devices(); init_key_mapping(); SDL_SysWMinfo info; SDL_VERSION(&info.version); // this is important! #if SDL_VERSION_ATLEAST(2, 0, 0) if (SDL_GetWindowWMInfo(g_fs_ml_window, &info)) { #else if (SDL_GetWMInfo(&info)) { #endif #if SDL_VERSION_ATLEAST(2, 0, 0) g_window = info.info.win.window; #else g_window = info.window; #endif //g_hglrc = info.hglrc; } g_wndproc = (WNDPROC) GetWindowLongPtr(g_window, GWLP_WNDPROC); SetWindowLongPtr(g_window, GWLP_WNDPROC, (LONG_PTR) WndProc); fs_log("old window proc: %p new window proc: %p\n", g_wndproc, WndProc); RAWINPUTDEVICE rid; /* // mice rid.usUsagePage = 0x01; rid.usUsage = 0x02; rid.dwFlags = 0; //rid.dwFlags = RIDEV_INPUTSINK; //rid.dwFlags = RIDEV_NOLEGACY; rid.hwndTarget = hWnd; RegisterRawInputDevices(&rid, 1, sizeof(rid)); */ // keyboards rid.usUsagePage = 0x01; rid.usUsage = 0x06; rid.dwFlags = RIDEV_NOLEGACY | RIDEV_NOHOTKEYS; rid.hwndTarget = g_window; RegisterRawInputDevices(&rid, 1, sizeof(rid)); g_keyboard_layout = GetKeyboardLayout(0); } #else int libfsemu_ml_rawinput_dummy;
bool Input::Mouse::Init(HWND* window) { RAWINPUTDEVICE Raw; Raw.hwndTarget = 0; Raw.usUsagePage = 0x01; Raw.usUsage = 0x02; Raw.dwFlags = 0; m_window = window; return (RegisterRawInputDevices(&Raw,1,sizeof(Raw)) == TRUE); }
void unregisterRawMice() { RAWINPUTDEVICE rawInputDevice; rawInputDevice.usUsagePage = HID_USAGE_PAGE_GENERIC; rawInputDevice.usUsage = HID_USAGE_GENERIC_MOUSE; rawInputDevice.dwFlags = RIDEV_REMOVE; rawInputDevice.hwndTarget = 0; if (RegisterRawInputDevices(&rawInputDevice, 1, sizeof(rawInputDevice)) != TRUE) { showErrorMessageAndExit(L"RegisterRawInputDevices()"); } }
bool RInput::register_device(RAWINPUTDEVICE& rid){ if(false == RInput::_initialised){ std::cerr << "RInput::register_device(): false == RInput::_initialised" << std::endl; return false; } if(TRUE != RegisterRawInputDevices(&rid, 1, sizeof(RAWINPUTDEVICE))){ std::cerr << "RInput::register_device(): TRUE != RegisterRawInputDevices(rid, 1, sizeof(RAWINPUTDEVICE))" << std::endl; return false; } return true; }
void Input::CaptureMouse(bool enable) { if(enable) { // capture mouse input so that stray clicks don't make the program lose focus RAWINPUTDEVICE devices[1]; devices[0].usUsagePage = HID_USAGE_PAGE_GENERIC; devices[0].usUsage = HID_USAGE_GENERIC_MOUSE; devices[0].dwFlags = RIDEV_NOLEGACY | RIDEV_CAPTUREMOUSE; devices[0].hwndTarget = window; RegisterRawInputDevices(devices, ARRAYSIZE(devices), sizeof(RAWINPUTDEVICE)); // hide cursor ShowCursor(FALSE); SetCursor(NULL); } else { // unregister so mouse stops being captured with RIDEV_CAPTUREMOUSE RAWINPUTDEVICE devices[1]; devices[0].usUsagePage = HID_USAGE_PAGE_GENERIC; devices[0].usUsage = HID_USAGE_GENERIC_MOUSE; devices[0].dwFlags = RIDEV_REMOVE; devices[0].hwndTarget = NULL; RegisterRawInputDevices(devices, ARRAYSIZE(devices), sizeof(RAWINPUTDEVICE)); // re-register mouse for raw input without the capture devices[0].usUsagePage = HID_USAGE_PAGE_GENERIC; devices[0].usUsage = HID_USAGE_GENERIC_MOUSE; devices[0].dwFlags = 0; devices[0].hwndTarget = window; RegisterRawInputDevices(devices, ARRAYSIZE(devices), sizeof(RAWINPUTDEVICE)); // show cursor //SetCursor(oldCursor); ShowCursor(TRUE); } }
//-------------------------------------------------------------------------------------- // Called every time the application receives a message //-------------------------------------------------------------------------------------- LRESULT CALLBACK InputWndProc( HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam ) { switch( message ) { case WM_NCCREATE: { RAWINPUTDEVICE Rid[1]; Rid[0].usUsagePage = HID_USAGE_PAGE_GENERIC; Rid[0].usUsage = HID_USAGE_GENERIC_MOUSE; Rid[0].dwFlags = RIDEV_INPUTSINK; Rid[0].hwndTarget = hWnd; RegisterRawInputDevices(Rid, 1, sizeof(Rid[0])); Rid[0].usUsagePage = HID_USAGE_PAGE_GENERIC; Rid[0].usUsage = HID_USAGE_GENERIC_KEYBOARD; Rid[0].dwFlags = RIDEV_INPUTSINK; Rid[0].hwndTarget = hWnd; RegisterRawInputDevices(Rid, 1, sizeof(Rid[0])); return TRUE; } case WM_INPUT: { s_pInput->ProcessInput(lParam); break; } case WM_DESTROY: { PostQuitMessage( 0 ); break; } default: return DefWindowProc( hWnd, message, wParam, lParam ); } return 0; }