void TestInputSystem::testKeyboardAutoRepeat() { InternalMessage("Input","Input::TestInputSystem::testKeyboardAutoRepeat entering") ; std::auto_ptr<Kernel::Model> model(new Kernel::Model("TestPlayerConfiguration::testKeyboardAutoRepeat")) ; model->init() ; Kernel::ControlerSet* controler_set = model->getControlerSet<Implementation::OIS::InputControlerSet>() ; controler_set->setTimeStep(0.01) ; Kernel::Object* root = model->createObject() ; root->addTrait(new Keyboard()) ; Implementation::OIS::Keyboard* keyboard = Implementation::OIS::getKeyboard() ; if (!keyboard) { std::cout << "warning : no keyboard found, skipping test" ; return ; } // send a key pressed ::OIS::KeyEvent keyboard_event(getOISKeyboard(),::OIS::KC_0,(unsigned int)'0') ; keyboard->keyPressed(keyboard_event) ; // count the actual interpreted key pressed events... Kernel::Timer global_timer ; Kernel::Timer timer ; const float simulation_time = 2 ; while (global_timer.getSecond() < simulation_time) { if (timer.getSecond() > 0.1) { model->update(timer.getSecond()) ; timer.reset() ; } } CPPUNIT_ASSERT_EQUAL((unsigned int)(simulation_time/ Kernel::Parameters::getValue<float>( "Input", "AutoRepeatDelay", Implementation::OIS::default_autorepeat_delay)), KeyboardListener::m_count) ; InternalMessage("Input","Input::TestInputSystem::testKeyboardAutoRepeat leaving") ; }
void process_events() { SDL_Event ev; while( SDL_PollEvent( &ev ) ) { switch(ev.type) { case SDL_QUIT: terminate_program(0);// never returns case SDL_KEYDOWN: keyboard_event(ev.key); break; default: break; } } }
void kbd_handle() { if (!keyboard_event) return; uint8_t code, character, down; code = inportb(0x60); static const uint8_t set1_map[] = { 0, KEY_ESCAPE, '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '-', '=', '\b', '\t', 'q', 'w', 'e', 'r', 't', 'y', 'u', 'i', 'o', 'p', '[', ']', '\n', KEY_LCTRL, 'a', 's', 'd', 'f', 'g', 'h', 'j', 'k', 'l', ';', '\'', '`', KEY_LSHIFT, '\\', 'z', 'x', 'c', 'v', 'b', 'n', 'm', ',', '.', '/', KEY_RSHIFT, '*', KEY_RALT, ' ', KEY_CAPS_LOCK, KEY_F1, KEY_F2, KEY_F3, KEY_F4, KEY_F5, KEY_F6, KEY_F7, KEY_F8, KEY_F9, KEY_F10, KEY_NUM_LOCK, KEY_SCRL_LOCK, KEY_HOME, KEY_UP, KEY_PGUP,'-', KEY_LFT,'5', KEY_RT, '+', KEY_END, KEY_DN, KEY_PGDN,KEY_INS,KEY_DEL,0, 0, 0, KEY_F11, KEY_F12 }; if(code >= 0x80) { code &= 0x7F; down = 0; } else down = 1; if(code >= sizeof(set1_map) / sizeof(set1_map[0])) return; keyboard_event(code, down); }
LRESULT CALLBACK window_proc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam ) { static int last_char_code = 0; switch ( uMsg ) { case WM_LBUTTONDOWN: { int x_pos = ( LOWORD( lParam ) * gTextureWidth ) / mAppWindowWidth; int y_pos = ( HIWORD( lParam ) * gTextureHeight ) / mAppWindowHeight; mouse_event( x_pos, y_pos, LLQtWebKit::ME_MOUSE_DOWN ); return 0; }; case WM_LBUTTONUP: { int x_pos = ( LOWORD( lParam ) * gTextureWidth ) / mAppWindowWidth; int y_pos = ( HIWORD( lParam ) * gTextureHeight ) / mAppWindowHeight; mouse_event( x_pos, y_pos, LLQtWebKit::ME_MOUSE_UP ); return 0; }; case WM_MOUSEMOVE: { int x_pos = ( LOWORD( lParam ) * gTextureWidth ) / mAppWindowWidth; int y_pos = ( HIWORD( lParam ) * gTextureHeight ) / mAppWindowHeight; mouse_event( x_pos, y_pos, LLQtWebKit::ME_MOUSE_MOVE ); return 0; }; case WM_CLOSE: { PostQuitMessage( 0 ); return 0; }; case WM_CHAR: { // pick up the character code here - keyboard event grabs virtual/scan // key codes set during WM_KEYDOWN last_char_code = (int)wParam; keyboard_event( last_char_code, LLQtWebKit::KE_KEY_DOWN ); return 0; }; case WM_KEYDOWN: { // no keyboard_event here because we don't know the character code here. // just save the wParam and lParam values - WM_CHAR will get sent next // and call keyboard_event with char code. gLParam = lParam; gWParam = wParam; if (nonprintable_key(wParam, &last_char_code)) { // this is not a printable key keyboard_event(last_char_code, LLQtWebKit::KE_KEY_DOWN); } else { // this is a printable, process in WM_CHAR } return 0; }; case WM_KEYUP: { // don't know what char code to send here - no WM_CHAR after a WM_KEYUP // in the same way WM_KEYDOWN works. keyboard_event( last_char_code, LLQtWebKit::KE_KEY_UP ); // not sure if we need yo update these here too? gLParam = lParam; gWParam = wParam; return 0; }; case WM_SIZE: { int new_width = LOWORD( lParam ); int new_height = HIWORD( lParam ); resize_gl_screen( new_width, new_height ); return 0; }; }; return DefWindowProc( hWnd, uMsg, wParam, lParam ); }
int main(int argc, char *argv[]) { int option; int option_index; int passes_through_deck = 3; int use_utf8 = 0; static const struct option options[] = { {"help", no_argument, NULL, 'h'}, {"version", no_argument, NULL, 'v'}, {"passes", required_argument, NULL, 'p'}, {"utf8", no_argument, NULL, 'u'} }; program_name = argv[0]; while ((option = getopt_long(argc, argv, "hvp:u", options, &option_index)) != -1) { switch (option) { case 'v': version(); exit(0); case 'p': passes_through_deck = atoi(optarg); break; case 'u': use_utf8 = true; break; case 'h': default: usage(program_name); exit(0); } } set_utf8_mode(use_utf8); setlocale(LC_ALL, ""); initscr(); raw(); noecho(); keypad(stdscr, TRUE); start_color(); curs_set(FALSE); set_escdelay(0); assume_default_colors(COLOR_WHITE, COLOR_GREEN); init_pair(1, COLOR_BLACK, COLOR_WHITE); init_pair(2, COLOR_RED, COLOR_WHITE); init_pair(3, COLOR_WHITE, COLOR_BLUE); init_pair(4, COLOR_WHITE, COLOR_GREEN); int key; while (!term_size_ok()) { clear(); mvprintw(1, 1, SMALL_TERM_MSG); refresh(); if ((key = getch()) == 'q' || key == 'Q') { endwin(); return(0); } } clear(); draw_greeting(); refresh(); for (;;) { if ((key = getch()) == 'q' || key == 'Q') { endwin(); return(0); } if (term_size_ok()) { clear(); draw_greeting(); refresh(); if (key == KEY_SPACEBAR) { clear(); refresh(); game_init(&game, passes_through_deck); break; } } else if (key == KEY_RESIZE) { clear(); mvprintw(1, 1, SMALL_TERM_MSG); refresh(); } } do { keyboard_event(getch()); } while (!game_won()); endwin(); game_end(); printf("You won.\n"); return(0); }