bool InputManager::Init() { // D E V I C E D E T E C T I O N //Keyboard if (GetKeyboardType(0)) //If the function fails and nTypeFlag, the return value is zero; _connectedDevices[Keyboard]=true; //Mouse if (GetSystemMetrics(SM_MOUSEPRESENT)) //Nonzero if a mouse is installed; _connectedDevices[Mouse]=true; //Gamepads XINPUT_STATE _controllerState; ZeroMemory(&_controllerState, sizeof(XINPUT_STATE)); for (int i=0;i<NUM_OF_GAMEPADS;i++) { DWORD Result = XInputGetState(0, &_controllerState); Result = XInputGetState(i, &_controllerState); if(Result == ERROR_SUCCESS) //true if gamepad #i is connected _connectedDevices[i]=true; } _init=IsOk(); return _init; }
bool InputManager::Init() { _myVirtualAxis = Array<VirtualAxis>(); _myVirtualButtons = Array<VirtualButton>(); _init = true; //deteccción de dispostivos, inicialización de los mismos if (GetKeyboardType(0) != 0) bool prueba = true; if (GetSystemMetrics(SM_MOUSEPRESENT)) bool prueba = true; return true; }
void keyboard() { int fkeyboard = 0; fkeyboard = GetKeyboardType(0); if ( fkeyboard == 0 ) { printf("该系统未找到键盘!\n"); } else { printf("存在键盘!\n"); } }
/****************************************************************************** * GetKeyboardType (KEYBOARD.130) */ INT16 WINAPI GetKeyboardType16(INT16 nTypeFlag) { return GetKeyboardType( nTypeFlag ); }
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPreInst, LPSTR lpszCmdLine, int nCmdShow) { WNDCLASS wc; MSG msg; HWND hWnd; int i; #ifdef OPENING_WAIT UINT32 tick; #endif _MEM_INIT(); GetModuleFileName(NULL, modulefile, NELEMENTS(modulefile)); dosio_init(); file_setcd(modulefile); np2arg_analize(); initload(); memdbg_readini(); skbdwin_readini(); rand_setseed((unsigned)time(NULL)); if ((hWnd = FindWindow(szClassName, NULL)) != NULL) { ShowWindow(hWnd, SW_RESTORE); SetForegroundWindow(hWnd); dosio_term(); return(FALSE); } hInst = hInstance; hPrev = hPreInst; TRACEINIT(); if (np2oscfg.KEYBOARD >= KEY_TYPEMAX) { // ver0.28 int keytype = GetKeyboardType(1); if ((keytype & 0xff00) == 0x0d00) { np2oscfg.KEYBOARD = KEY_PC98; } else if (!keytype) { np2oscfg.KEYBOARD = KEY_KEY101; } else { np2oscfg.KEYBOARD = KEY_KEY106; } } keystat_initialize(); if (!hPreInst) { wc.style = CS_BYTEALIGNCLIENT | CS_HREDRAW | CS_VREDRAW; wc.lpfnWndProc = WndProc; wc.cbClsExtra = 0; wc.cbWndExtra = 0; wc.hInstance = hInstance; wc.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_ICON1)); wc.hCursor = LoadCursor(NULL, IDC_ARROW); wc.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH); wc.lpszMenuName = MAKEINTRESOURCE(IDR_MAIN); wc.lpszClassName = szClassName; if (!RegisterClass(&wc)) { return(FALSE); } } memdbg_initialize(hInstance); skbdwin_initialize(hInstance); mousemng_initialize(); hWnd = CreateWindowEx(0, szClassName, szAppCaption, WS_OVERLAPPED | WS_SYSMENU | WS_CAPTION | WS_MINIMIZEBOX, np2oscfg.winx, np2oscfg.winy, 640, 400, NULL, NULL, hInstance, NULL); hWndMain = hWnd; scrnmng_initialize(); xmenu_setroltate(0); xmenu_setdispmode(np2cfg.DISPSYNC); xmenu_setraster(np2cfg.RASTER); xmenu_setwaitflg(np2oscfg.NOWAIT); xmenu_setframe(np2oscfg.DRAW_SKIP); xmenu_setkey(0); xmenu_setxshift(0); xmenu_setf12copy(np2oscfg.F12COPY); xmenu_setbeepvol(np2cfg.BEEP_VOL); xmenu_setsound(np2cfg.SOUND_SW); xmenu_setjastsound(np2oscfg.jastsnd); xmenu_setmotorflg(np2cfg.MOTOR); xmenu_setextmem(np2cfg.EXTMEM); xmenu_setmouse(np2oscfg.MOUSE_SW); xmenu_setbtnmode(np2cfg.BTN_MODE); xmenu_setbtnrapid(np2cfg.BTN_RAPID); xmenu_setmsrapid(np2cfg.MOUSERAPID); ShowWindow(hWnd, nCmdShow); UpdateWindow(hWnd); #ifdef OPENING_WAIT tick = GetTickCount(); #endif sysmenu_initialize(); xmenu_initialize(); DrawMenuBar(hWnd); // ver0.30 if (file_attr_c(np2help) == (short)-1) { EnableMenuItem(GetMenu(hWnd), IDM_HELP, MF_GRAYED); } scrnmode = 0; if (np2arg.fullscreen) { scrnmode |= SCRNMODE_FULLSCREEN; } if (np2cfg.RASTER) { scrnmode |= SCRNMODE_HIGHCOLOR; } if (scrnmng_create(scrnmode) != SUCCESS) { scrnmode ^= SCRNMODE_FULLSCREEN; if (scrnmng_create(scrnmode) != SUCCESS) { MessageBox(hWnd, _T("Couldn't create DirectDraw Object"), szAppCaption, MB_OK | MB_ICONSTOP); return(FALSE); } } soundmng_initialize(); if (np2oscfg.MOUSE_SW) { // ver0.30 mousemng_enable(MOUSEPROC_SYSTEM); } commng_initialize(); sysmng_initialize(); joy_init(); pccore_init(); S98_init(); #ifdef OPENING_WAIT while((GetTickCount() - tick) < OPENING_WAIT); #endif scrndraw_redraw(); pccore_reset(); np2opening = 0; // れじうむ #if defined(SUPPORT_RESUME) if (np2oscfg.resume) { int id; id = flagload(str_sav, str_resume, FALSE); if (id == IDYES) { for (i=0; i<4; i++) np2arg.disk[i] = NULL; } else if (id == IDCANCEL) { DestroyWindow(hWnd); mousemng_disable(MOUSEPROC_WINUI); S98_trash(); pccore_term(); soundmng_deinitialize(); scrnmng_destroy(); TRACETERM(); dosio_term(); return(0); } } #endif // リセットしてから… コマンドラインのディスク挿入。 // ver0.29 for (i=0; i<4; i++) { if (np2arg.disk[i]) { diskdrv_readyfdd((REG8)i, np2arg.disk[i], 0); } } memdbg_create(); skbdwin_create(); while(1) { if (PeekMessage(&msg, 0, 0, 0, PM_NOREMOVE)) { if (!GetMessage(&msg, NULL, 0, 0)) { break; } if ((msg.message != WM_SYSKEYDOWN) && (msg.message != WM_SYSKEYUP)) { TranslateMessage(&msg); } DispatchMessage(&msg); } else { if (np2oscfg.NOWAIT) { joy_flash(); mousemng_sync(); pccore_exec(framecnt == 0); if (np2oscfg.DRAW_SKIP) { // nowait frame skip framecnt++; if (framecnt >= np2oscfg.DRAW_SKIP) { processwait(0); } } else { // nowait auto skip framecnt = 1; if (timing_getcount()) { processwait(0); } } } else if (np2oscfg.DRAW_SKIP) { // frame skip if (framecnt < np2oscfg.DRAW_SKIP) { joy_flash(); mousemng_sync(); pccore_exec(framecnt == 0); framecnt++; } else { processwait(np2oscfg.DRAW_SKIP); } } else { // auto skip if (!waitcnt) { UINT cnt; joy_flash(); mousemng_sync(); pccore_exec(framecnt == 0); framecnt++; cnt = timing_getcount(); if (framecnt > cnt) { waitcnt = framecnt; if (framemax > 1) { framemax--; } } else if (framecnt >= framemax) { if (framemax < 12) { framemax++; } if (cnt >= 12) { timing_reset(); } else { timing_setcount(cnt - framecnt); } framereset(); } } else { processwait(waitcnt); waitcnt = framecnt; } } } } pccore_cfgupdate(); mousemng_disable(MOUSEPROC_WINUI); S98_trash(); #if defined(SUPPORT_RESUME) if (np2oscfg.resume) { flagsave(str_sav); } else { flagdelete(str_sav); } #endif pccore_term(); memdbg_destroy(); skbdwin_destroy(); soundmng_deinitialize(); scrnmng_destroy(); if (sys_updates & (SYS_UPDATECFG | SYS_UPDATEOSCFG)) { initsave(); memdbg_writeini(); skbdwin_writeini(); } skbdwin_deinitialize(); TRACETERM(); _MEM_USED("report.txt"); dosio_term(); return static_cast<int>(msg.wParam); }
/* Set the keyboard configuration */ Bool winConfigKeyboard(DeviceIntPtr pDevice) { char layoutName[KL_NAMELENGTH]; unsigned char layoutFriendlyName[256]; unsigned int layoutNum = 0; unsigned int deviceIdentifier = 0; int keyboardType; #ifdef XWIN_XF86CONFIG XF86ConfInputPtr kbd = NULL; XF86ConfInputPtr input_list = NULL; MessageType kbdfrom = X_CONFIG; #endif MessageType from = X_DEFAULT; char *s = NULL; /* Setup defaults */ XkbGetRulesDflts(&g_winInfo.xkb); /* * Query the windows autorepeat settings and change the xserver defaults. */ { int kbd_delay; DWORD kbd_speed; if (SystemParametersInfo(SPI_GETKEYBOARDDELAY, 0, &kbd_delay, 0) && SystemParametersInfo(SPI_GETKEYBOARDSPEED, 0, &kbd_speed, 0)) { switch (kbd_delay) { case 0: g_winInfo.keyboard.delay = 250; break; case 1: g_winInfo.keyboard.delay = 500; break; case 2: g_winInfo.keyboard.delay = 750; break; default: case 3: g_winInfo.keyboard.delay = 1000; break; } g_winInfo.keyboard.rate = (kbd_speed > 0) ? kbd_speed : 1; winDebug("Setting autorepeat to delay=%ld, rate=%ld\n", g_winInfo.keyboard.delay, g_winInfo.keyboard.rate); } } keyboardType = GetKeyboardType(0); if (keyboardType > 0 && GetKeyboardLayoutName(layoutName)) { WinKBLayoutPtr pLayout; Bool bfound = FALSE; int pass; layoutNum = strtoul(layoutName, (char **) NULL, 16); if ((layoutNum & 0xffff) == 0x411) { if (keyboardType == 7) { /* Japanese layouts have problems with key event messages such as the lack of WM_KEYUP for Caps Lock key. Loading US layout fixes this problem. */ if (LoadKeyboardLayout("00000409", KLF_ACTIVATE) != NULL) winDebug("Loading US keyboard layout.\n"); else ErrorF ("LoadKeyboardLayout failed.\n"); } } /* Discover the friendly name of the current layout */ { HKEY regkey = NULL; const char regtempl[] = "SYSTEM\\CurrentControlSet\\Control\\Keyboard Layouts\\"; char *regpath; DWORD namesize = sizeof(layoutFriendlyName); regpath = malloc(sizeof(regtempl) + KL_NAMELENGTH + 1); strcpy(regpath, regtempl); strcat(regpath, layoutName); if (!RegOpenKey(HKEY_LOCAL_MACHINE, regpath, ®key)) RegQueryValueEx(regkey, "Layout Text", 0, NULL, layoutFriendlyName, &namesize); /* Close registry key */ if (regkey) RegCloseKey(regkey); free(regpath); } winDebug ("Windows keyboard layout: \"%s\" (%08x) \"%s\", type %d\n", layoutName, layoutNum, layoutFriendlyName, keyboardType); deviceIdentifier = layoutNum >> 16; for (pass = 0; pass < 2; pass++) { /* If we didn't find an exact match for the input locale identifer, try to find an match on the language identifier part only */ if (pass == 1) layoutNum = (layoutNum & 0xffff); for (pLayout = winKBLayouts; pLayout->winlayout != -1; pLayout++) { if (pLayout->winlayout != layoutNum) continue; if (pLayout->winkbtype > 0 && pLayout->winkbtype != keyboardType) continue; bfound = TRUE; winDebug ( "Found matching XKB configuration \"%s\"\n", pLayout->layoutname); winDebug( "Model = \"%s\" Layout = \"%s\"" " Variant = \"%s\" Options = \"%s\"\n", pLayout->xkbmodel ? pLayout->xkbmodel : "none", pLayout->xkblayout ? pLayout->xkblayout : "none", pLayout->xkbvariant ? pLayout->xkbvariant : "none", pLayout->xkboptions ? pLayout->xkboptions : "none"); g_winInfo.xkb.model = (char *)pLayout->xkbmodel; g_winInfo.xkb.layout = (char *)pLayout->xkblayout; g_winInfo.xkb.variant = (char *)pLayout->xkbvariant; g_winInfo.xkb.options = (char *)pLayout->xkboptions; if (deviceIdentifier == 0xa000) { winDebug("Windows keyboard layout device identifier indicates Macintosh, setting Model = \"macintosh\""); g_winInfo.xkb.model = "macintosh"; } break; } if (bfound) break; } if (!bfound) { ErrorF ("Keyboardlayout \"%s\" (%s) is unknown, using X server default layout\n", layoutFriendlyName, layoutName); } }
// Inicialición: deteccción de dispostivos, inicialización de los mismos... etc bool InputManager::Init() { keys.Add(Key( Mouse_Button0 ) ); keys.Add(Key( Mouse_Button1 ) ); keys.Add(Key( Mouse_Button2 ) ); keys.Add(Key( Mouse_WheelDown ) ); keys.Add(Key( Mouse_WheelUp) ); keys.Add(Key( Mouse_Down) ); keys.Add(Key( Mouse_Up) ); keys.Add(Key( Mouse_Left) ); keys.Add(Key( Mouse_Right) ); keys.Add(Key( JOYSTICK_1) ); keys.Add(Key( JOYSTICK_2) ); keys.Add(Key( JOYSTICK_3) ); keys.Add(Key( JOYSTICK_4) ); keys.Add(Key( JOYSTICK_5) ); keys.Add(Key( JOYSTICK_6) ); keys.Add(Key( JOYSTICK_7) ); keys.Add(Key( JOYSTICK_8) ); keys.Add(Key( JOYSTICK_9) ); keys.Add(Key( JOYSTICK_10) ); keys.Add(Key( JOYSTICK_11) ); keys.Add(Key( JOYSTICK_12) ); keys.Add(Key( JOYSTICK_13) ); keys.Add(Key( JOYSTICK_14) ); keys.Add(Key( JOYSTICK_15) ); keys.Add(Key( JOYSTICK_16) ); keys.Add(Key( Key_0) ); keys.Add(Key( Key_1) ); keys.Add(Key( Key_2) ); keys.Add(Key( Key_3) ); keys.Add(Key( Key_4) ); keys.Add(Key( Key_5) ); keys.Add(Key( Key_6) ); keys.Add(Key( Key_7) ); keys.Add(Key( Key_8) ); keys.Add(Key( Key_9) ); keys.Add(Key( Key_A) ); keys.Add(Key( Key_B) ); keys.Add(Key( Key_C) ); keys.Add(Key( Key_D) ); keys.Add(Key( Key_E) ); keys.Add(Key( Key_F) ); keys.Add(Key( Key_G) ); keys.Add(Key( Key_H) ); keys.Add(Key( Key_I) ); keys.Add(Key( Key_J) ); keys.Add(Key( Key_K) ); keys.Add(Key( Key_L) ); keys.Add(Key( Key_M) ); keys.Add(Key( Key_N) ); keys.Add(Key( Key_O) ); keys.Add(Key( Key_P) ); keys.Add(Key( Key_Q) ); keys.Add(Key( Key_R) ); keys.Add(Key( Key_S) ); keys.Add(Key( Key_T) ); keys.Add(Key( Key_U) ); keys.Add(Key( Key_V) ); keys.Add(Key( Key_W) ); keys.Add(Key( Key_X) ); keys.Add(Key( Key_Y) ); keys.Add(Key( Key_Z) ); keys.Add(Key( Key_F1) ); keys.Add(Key( Key_F2) ); keys.Add(Key( Key_F3) ); keys.Add(Key( Key_F4) ); keys.Add(Key( Key_F5) ); keys.Add(Key( Key_F6) ); keys.Add(Key( Key_F7) ); keys.Add(Key( Key_F8) ); keys.Add(Key( Key_F9) ); keys.Add(Key( Key_F10) ); keys.Add(Key( Key_F11) ); keys.Add(Key( Key_F12) ); keys.Add(Key( Key_F13) ); keys.Add(Key( Key_F14) ); keys.Add(Key( Key_F15) ); keys.Add(Key( Key_UpArrow) ); keys.Add(Key( Key_DownArrow) ); keys.Add(Key( Key_LeftArrow) ); keys.Add(Key( Key_RightArrow) ); keys.Add(Key( Key_AltGr) ); keys.Add(Key( Key_Ampersand) ); keys.Add(Key( Key_Asterisk) ); keys.Add(Key( Key_At) ); keys.Add(Key( Key_BackQuote) ); keys.Add(Key( Key_Backslash) ); keys.Add(Key( Key_Backspace) ); keys.Add(Key( Key_Break) ); keys.Add(Key( Key_CapsLock) ); keys.Add(Key( Key_Caret) ); keys.Add(Key( Key_Clear) ); keys.Add(Key( Key_Colon) ); keys.Add(Key( Key_Comma) ); keys.Add(Key( Key_Delete) ); keys.Add(Key( Key_Dollar) ); keys.Add(Key( Key_DoubleQuote) ); keys.Add(Key( Key_End) ); keys.Add(Key( Key_Equals) ); keys.Add(Key( Key_Escape) ); keys.Add(Key( Key_Exclaim) ); keys.Add(Key( Key_Greater) ); keys.Add(Key( Key_Hash) ); keys.Add(Key( Key_Help) ); keys.Add(Key( Key_Home) ); keys.Add(Key( Key_Insert) ); keys.Add(Key( Key_Keypad0) ); keys.Add(Key( Key_Keypad1) ); keys.Add(Key( Key_Keypad2) ); keys.Add(Key( Key_Keypad3) ); keys.Add(Key( Key_Keypad4) ); keys.Add(Key( Key_Keypad5) ); keys.Add(Key( Key_Keypad6) ); keys.Add(Key( Key_Keypad7) ); keys.Add(Key( Key_Keypad8) ); keys.Add(Key( Key_Keypad9) ); keys.Add(Key( Key_KeypadDivide) ); keys.Add(Key( Key_KeypadEnter) ); keys.Add(Key( Key_KeypadEquals) ); keys.Add(Key( Key_KeypadMinus) ); keys.Add(Key( Key_KeypadMultiply) ); keys.Add(Key( Key_KeypadPeriod) ); keys.Add(Key( Key_KeypadPlus) ); keys.Add(Key( Key_LeftAlt) ); keys.Add(Key( Key_LeftApple) ); keys.Add(Key( Key_LeftBracket) ); keys.Add(Key( Key_LeftControl) ); keys.Add(Key( Key_LeftParen) ); keys.Add(Key( Key_LeftShift) ); keys.Add(Key( Key_LeftWindows) ); keys.Add(Key( Key_Less) ); keys.Add(Key( Key_Menu) ); keys.Add(Key( Key_Minus) ); keys.Add(Key( Key_Numlock) ); keys.Add(Key( Key_PageDown) ); keys.Add(Key( Key_PageUp) ); keys.Add(Key( Key_Pause) ); keys.Add(Key( Key_Period) ); keys.Add(Key( Key_Plus) ); keys.Add(Key( Key_Print) ); keys.Add(Key( Key_Question) ); keys.Add(Key( Key_Quote) ); keys.Add(Key( Key_Return) ); keys.Add(Key( Key_RightAlt) ); keys.Add(Key( Key_RightApple) ); keys.Add(Key( Key_RightBracket) ); keys.Add(Key( Key_RightControl) ); keys.Add(Key( Key_RightParen) ); keys.Add(Key( Key_RightShift) ); keys.Add(Key( Key_RightWindows) ); keys.Add(Key( Key_ScrollLock) ); keys.Add(Key( Key_Semicolon) ); keys.Add(Key( Key_Slash) ); keys.Add(Key( Key_Space) ); keys.Add(Key( Key_SysReq) ); keys.Add(Key( Key_Tab) ); keys.Add(Key( Key_Underscore) ); keys.Add(Key( Button_Up ) ); keys.Add(Key( Button_Down ) ); keys.Add(Key( Button_Left ) ); keys.Add(Key( Button_Right ) ); keys.Add(Key( Button_Start ) ); keys.Add(Key( Button_Back ) ); keys.Add(Key( Button_LB ) ); keys.Add(Key( Button_RB ) ); keys.Add(Key( Button_A ) ); keys.Add(Key( Button_B ) ); keys.Add(Key( Button_X ) ); keys.Add(Key( Button_Y ) ); keys.Add(Key( Button_LT ) ); keys.Add(Key( Button_RT ) ); keys.Add(Key( Button_LX_POS ) ); keys.Add(Key( Button_LX_NEG ) ); keys.Add(Key( Button_LY_POS ) ); keys.Add(Key( Button_LY_NEG ) ); keys.Add(Key( Button_RX_POS ) ); keys.Add(Key( Button_RX_NEG ) ); keys.Add(Key( Button_RY_POS ) ); keys.Add(Key( Button_RY_NEG ) ); xMouse = yMouse = 0; if( GetKeyboardType( 0 ) ) { devicesOn[ Keyboard ] = true; } else { devicesOn[ Keyboard ] = false; } if( GetSystemMetrics( SM_MOUSEPRESENT ) ) { devicesOn[ Mouse ] = true; } else { devicesOn[ XboxPad ] = false; } // XINPUT_STATE state; // ZeroMemory( &state, sizeof(state)); /*if( XInputGetState( 0, &state) == ERROR_SUCCESS ) { devicesOn[ XboxPad ] = true; } else { devicesOn[ XboxPad ] = false; }*/ return isOk = devicesOn[ Keyboard ] && devicesOn[ Mouse ] ; }