internal void hh_process_events(android_app *app, game_input *new_input, game_input *old_input) { game_controller_input *old_controller = GetController(old_input, 1); game_controller_input *new_controller = GetController(new_input, 1); user_data *p = (user_data *)app->userData; pan_state *pan = &p->motion.pan; process_button((pan->stick.X > 0), &old_controller->MoveRight, &new_controller->MoveRight); process_button((pan->stick.X < 0), &old_controller->MoveLeft, &new_controller->MoveLeft); process_button((pan->stick.Y > 0), &old_controller->MoveUp, &new_controller->MoveUp); process_button((pan->stick.Y < 0), &old_controller->MoveDown, &new_controller->MoveDown); }
static void sdl_process_controller_input(SDL_GameController* controller, input_state_t* input_state) { controller = grab_controller(controller); if (controller) { process_button(&input_state->move_up, SDL_GameControllerGetButton(controller, SDL_CONTROLLER_BUTTON_DPAD_UP)); process_button(&input_state->move_down, SDL_GameControllerGetButton(controller, SDL_CONTROLLER_BUTTON_DPAD_DOWN)); process_button(&input_state->move_left, SDL_GameControllerGetButton(controller, SDL_CONTROLLER_BUTTON_DPAD_LEFT)); process_button(&input_state->move_right, SDL_GameControllerGetButton(controller, SDL_CONTROLLER_BUTTON_DPAD_RIGHT)); } else { memset(input_state, 0, sizeof(input_state_t)); } return; }
void processobj(tgui_Window *win, tgui_Obj *obj){ do { switch (obj->objtype){ case label : break; case button: process_button(win, obj); break; case simpletext : process_simpletext(win, obj); break; case numbox: process_numbox(win, obj); break; case checkbox: process_checkbox(win, obj); break; case listbox: process_listbox(win, obj); break; default : break; } // switch obj=obj->next; if (obj==NULL) obj=win->firstobj; }while (win->quitflag == 0); } // end processobj
void kos_Main() { kos_InitHeap(); load_edit_box(); init(); for (;;) { switch (kos_WaitForEvent()) { case 6: process_mouse(); break; case 1: window_drawall=true; draw_window(); break; case 2: process_key(); break; case 3: process_button(); break; } } }
int main(int argc, char* argv[]) { init(); if (argc > 1) load_mappings(argv[1]); printf("Listening for gamepads...\n"); while (1) { SDL_WaitEvent(NULL); SDL_Event event; while (SDL_PollEvent(&event)) { if (event.type == SDL_QUIT) { quit(); } else if (event.type == SDL_CONTROLLERDEVICEADDED) { printf("Gamepad connected (index: %d)\n", event.cdevice.which); add_controller(event.cdevice.which); } else if (event.type == SDL_CONTROLLERDEVICEREMOVED) { printf("Gamepad disconnected (instance id: %d)\n", event.cdevice.which); // Close the controller and free its slot in our array (if it // is currently in our array) remove_controller(event.cdevice.which); } else if (event.type == SDL_CONTROLLERBUTTONDOWN) { process_button(event.cbutton.which, event.cbutton.button); } } } return 0; }
/* TODO(lars): handle minimization, lost focus, etc... */ static void sdl_process_keyboard_input(SDL_Window* window, input_state_t* input_state) { SDL_Event event; while(SDL_PollEvent(&event)) { if (event.type == SDL_QUIT || (event.type == SDL_KEYDOWN && event.key.keysym.sym == SDLK_q)) { global_is_running = 0; } else if (event.type == SDL_KEYUP && event.key.keysym.sym == SDLK_f) { int32_t is_fullscreen; /* TODO(lars): once supported, switch to SDL_WINDOW_FULLSCREEN (the true videomode) */ is_fullscreen = (SDL_GetWindowFlags(window) & SDL_WINDOW_FULLSCREEN_DESKTOP); if (SDL_SetWindowFullscreen(window, is_fullscreen ? 0 : SDL_WINDOW_FULLSCREEN_DESKTOP) != 0) { /* TODO(lars): logging */ } global_refresh_rate = sdl_get_refresh_rate(window); } else if (event.type == SDL_KEYUP || event.type == SDL_KEYDOWN) { bool32_t is_down = (event.type == SDL_KEYDOWN); switch (event.key.keysym.sym) { case (SDLK_w): case (SDLK_UP): process_button(&input_state->move_up, is_down); break; case (SDLK_a): case (SDLK_LEFT): process_button(&input_state->move_left, is_down); break; case (SDLK_s): case (SDLK_DOWN): process_button(&input_state->move_down, is_down); break; case (SDLK_d): case (SDLK_RIGHT): process_button(&input_state->move_right, is_down); break; default: break; } } } return; }
bool dev::sixense::process_event(app::event *E) { switch (E->get_type()) { case E_POINT: if (process_point (E)) return true; else break; case E_AXIS: if (process_axis (E)) return true; else break; case E_BUTTON: if (process_button(E)) return true; else break; case E_TICK: if (process_tick (E)) return true; else break; } return dev::input::process_event(E); }
int main(int argc, char **argv) { Display *display; Window win; //窗口ID Window win_draw; unsigned int width, height; //窗口尺寸 unsigned int border_width = 4; //边界空白 unsigned int display_width, display_height;//屏幕尺寸 int i; int count; XEvent report; unsigned long valuemask = 0; XGCValues values; char *getenv(); XColor color; //draw int x1, y1, x2, y2; // 和X 服务器连接 if ( (display=XOpenDisplay(getenv("DISPLAY"))) == NULL ){ printf("Cannot connect to X server %s"); exit(-1); } //获得缺省的 screen_num screen_num = DefaultScreen(display); //获得屏幕的宽度和高度 display_width = DisplayWidth(display, screen_num); display_height = DisplayHeight(display, screen_num); cmap = DefaultColormap(display, screen_num); //指定所建立窗口的宽度和高度 width = display_width/2; height = display_height/2; //建立窗口 win = XCreateSimpleWindow(display, //display RootWindow(display,screen_num), //父窗口 0, 0, width, height, //位置和大小 border_width, //边界宽度 BlackPixel(display,screen_num), //前景色 WhitePixel(display,screen_num));//背景色 //选择窗口感兴趣的事件掩码 XSelectInput(display, win, ExposureMask | ButtonPressMask | //按下 ButtonReleaseMask | //抬起 ButtonMotionMask | //移动 KeyPressMask | StructureNotifyMask); //建立GC gc = XCreateGC(display, win, valuemask, &values); XSetLineAttributes(display, gc, 3, LineSolid, CapRound, JoinRound); panelgc = create_gc(display, win, "#C0C0C0"); dimgc = create_gc(display, win, "#666666"); lightgc = create_gc(display, win, "#F5F5F5"); //建立绘图窗口 win_draw = XCreateSimpleWindow(display, //display win, //父窗口 10, 10, width - 140,height - 40,//位置和大小 border_width, //边界宽度 BlackPixel(display,screen_num), //前景色 WhitePixel(display,screen_num));//背景色 //选择窗口感兴趣的事件掩码 XSelectInput(display, win_draw, ExposureMask | ButtonPressMask | //按下 ButtonReleaseMask | //抬起 ButtonMotionMask | //移动 KeyPressMask | StructureNotifyMask); //建立按钮窗口 for(i=0; i<4; i++) create_button(i, display, win, width - 100, i * 30 + 30, 80, 20); //显示窗口 XMapWindow(display, win); XMapWindow(display, win_draw); //进入事件循环 while (1) { //取得队列中的事件 XNextEvent(display, &report); switch (report.type) { //曝光事件, 窗口应重绘 case Expose: //取得最后一个曝光事件 if (report.xexpose.count != 0) break; XClearArea(display, win, 0, 0, width, height, False); for(i=0;i<4;i++) button_flush(i, display); break; //窗口尺寸改变, 重新取得窗口的宽度和高度 case ConfigureNotify: width = report.xconfigure.width; height = report.xconfigure.height; break; //鼠标左键开始绘图. case ButtonPress: if(report.xbutton.button == Button1 && report.xbutton.window == win_draw){ x1 = report.xbutton.x; y1 = report.xbutton.y; XDrawPoint(display, win_draw, gc,x1,y1); } else if(report.xbutton.button == Button1 && report.xbutton.window == buttons[0].win){ process_button(0, display); } else if(report.xbutton.button == Button1 && report.xbutton.window == buttons[1].win){ process_button(1, display); } else if(report.xbutton.button == Button1 && report.xbutton.window == buttons[2].win){ process_button(2, display); } else if(report.xbutton.button == Button1 && report.xbutton.window == buttons[3].win){ process_button(3, display); } else if(report.xbutton.button == Button3){ XFreeGC(display, gc); exit(1); } break; case ButtonRelease: if(report.xbutton.button == Button1 && report.xbutton.window == win_draw){ x2 = report.xbutton.x; y2 = report.xbutton.y; XDrawLine(display, win_draw, gc, x1, y1, x2, y2); } break; case MotionNotify: if(report.xmotion.state & Button1Mask && report.xmotion.window == win_draw){ x2 = report.xmotion.x; y2 = report.xmotion.y; XDrawLine(display, win_draw, gc, x1, y1, x2, y2); x1 = x2; y1 = y2; } break; case KeyPress: XFreeGC(display, gc); exit(1); default: break; } } }
int joystick(void) { static bool key_cursorup = false; static bool key_cursordown = false; static bool key_cursorleft = false; static bool key_cursorright = false; static bool warp_mode=false; // osk_active_bufferlen == The OSK is entering characters, don't interrupt it. // autostart_in_progress() == // Autostart is running. Don't allow the joystick to interrupt. // In particular this can break the actual autostart script that tests the basic prompt due to interference if (osk_active_bufferlen || autostart_in_progress()) { return 0; } uint8_t pads_connected = CellInput->NumberPadsConnected(); for (uint8_t i = 0; i < pads_connected; ++i) { int value = 0; // Do PS3 pads CellInput->UpdateDevice(i); // Set the joystick values if (CellInput->IsButtonPressed(i,CTRL_LEFT) | CellInput->IsAnalogPressedLeft(i,CTRL_LSTICK)) value |= 4; if (CellInput->IsButtonPressed(i,CTRL_RIGHT) | CellInput->IsAnalogPressedRight(i,CTRL_LSTICK)) value |= 8; if (CellInput->IsButtonPressed(i,CTRL_UP) | CellInput->IsAnalogPressedUp(i,CTRL_LSTICK)) value |= 1; if (CellInput->IsButtonPressed(i,CTRL_DOWN) | CellInput->IsAnalogPressedDown(i,CTRL_LSTICK)) value |= 2; // Process re-definable controls process_button (i, CTRL_CROSS, &value); process_button (i, CTRL_CIRCLE, &value); process_button (i, CTRL_SQUARE, &value); process_button (i, CTRL_TRIANGLE, &value); process_button (i, CTRL_L1, &value); process_button (i, CTRL_L2, &value); process_button (i, CTRL_R1, &value); process_button (i, CTRL_R2, &value); // Emulator cursor keys if (CellInput->IsAnalogPressedUp(i,CTRL_RSTICK)) { if (!key_cursorup) { keyboard_key_pressed((signed long) 32850); // Cursor Up key pressed key_cursorup = true; } } else { if (key_cursorup) { keyboard_key_released((signed long) 32850); // Cursor Up key released key_cursorup = false; } } if (CellInput->IsAnalogPressedDown(i,CTRL_RSTICK)) { if (!key_cursordown) { keyboard_key_pressed((signed long) 32849); // Cursor Down key pressed key_cursordown = true; } } else { if (key_cursordown) { keyboard_key_released((signed long) 32849); // Cursor Down key released key_cursordown = false; } } if (CellInput->IsAnalogPressedLeft(i,CTRL_RSTICK)) { if (!key_cursorleft) { keyboard_key_pressed((signed long) 32848); // Cursor Left key pressed key_cursorleft = true; } } else { if (key_cursorleft) { keyboard_key_released((signed long) 32848); // Cursor Left key released key_cursorleft = false; } } if (CellInput->IsAnalogPressedRight(i,CTRL_RSTICK)) { if (!key_cursorright) { keyboard_key_pressed((signed long) 32847); // Cursor Right key pressed key_cursorright = true; } } else { if (key_cursorright) { keyboard_key_released((signed long) 32847); // Cursor Right key released key_cursorright = false; } } if ((CellInput->IsButtonPressed(0,CTRL_R2) && CellInput->IsButtonPressed(0,CTRL_L2)) || (CellInput->IsButtonPressed(1,CTRL_R2) && CellInput->IsButtonPressed(1,CTRL_L2))) { if (!warp_mode) { // Disable sound (makes warp mode infinitely faster) resources_set_int("Sound", 0); // Enable Warp Mode resources_set_int("WarpMode", 1); warp_mode=true; } } else { if (warp_mode) { resources_set_int("WarpMode", 0); resources_set_int("Sound", 1); warp_mode=false; } } if (CellInput->IsButtonPressed(i,CTRL_L1) && CellInput->IsButtonPressed(i,CTRL_R1) && CellInput->IsButtonPressed(i,CTRL_L2) && CellInput->IsButtonPressed(i,CTRL_R2) ) machine_trigger_reset(MACHINE_RESET_MODE_HARD); /* // Swap joysticks if (CellInput->WasButtonPressed(i,CTRL_SELECT)) { // Do nothing } // Required because keyloop kills us if (CellInput->WasButtonReleased(i,CTRL_SELECT)) { if (pads_connected == 1) // Only allow us to swap joystick ports if there is only one controller // Otherwise, multiplayer madness and much punching will ensue. joyswap=!joyswap; } */ if (CellInput->WasButtonPressed(i,CTRL_SELECT)) InGameMenuLoop(); if(CellInput->WasButtonPressed(i,CTRL_START)) { menu(MODE_MENU); // Stop the clock (effectively, tells the emulator we were paused) vsync_suspend_speed_eval(); // Apply any changes as necessary. } if(CellInput->WasButtonPressed(i,CTRL_L3)) { // Vice OSK menu(MODE_OSK); // Stop the clock (effectively, tells the emulator we were paused) vsync_suspend_speed_eval(); // Apply any changes as necessary. } if(CellInput->WasButtonPressed(i,CTRL_R3)) { osk->Start(L"Characters entered here will be relayed to the emulator ", L""); #ifdef CELL_DEBUG printf("OSK started\n"); #endif // Just in case. This ensures we check to see if the screen has updated, and if not.. force one // The OSK fails to draw if the screen doesn't update. } cellSysutilCheckCallback(); if (sysutil_drawing) sysutil_callback_redraw(); ui_callback(); // pad 0 becomes port 2 // pad 1 becomes port 1 if (joyswap) joystick_set_value_absolute( ((i+1) % 2 ) + 1, value); else joystick_set_value_absolute(i+1, value); // pad 0 becomes port 1 // pad 1 becomes port 2 } return 0; }
internal void process_joysticks(struct sdl_event_context *ctx, struct human_input *old_input, struct human_input *new_input) { unsigned int i; struct game_controller_input *old_controller_input, *new_controller_input; int stick_x, stick_y; /* DPAD unsigned int up, down, left, right, start, back; */ for (i = 0; i < MAX_CONTROLLERS; ++i) { if (!(ctx->players[i].controller)) { continue; } if (!SDL_GameControllerGetAttached(ctx->players[i].controller)) { continue; } old_controller_input = &old_input->controllers[i]; new_controller_input = &new_input->controllers[i]; new_controller_input->is_analog = 1; /* up = SDL_GameControllerGetButton(ctx->players[i].controller, SDL_CONTROLLER_BUTTON_DPAD_UP); down = SDL_GameControllerGetButton(ctx->players[i].controller, SDL_CONTROLLER_BUTTON_DPAD_DOWN); left = SDL_GameControllerGetButton(ctx->players[i].controller, SDL_CONTROLLER_BUTTON_DPAD_LEFT); right = SDL_GameControllerGetButton(ctx->players[i].controller, SDL_CONTROLLER_BUTTON_DPAD_RIGHT); start = SDL_GameControllerGetButton(ctx->players[i].controller, SDL_CONTROLLER_BUTTON_START); back = SDL_GameControllerGetButton(ctx->players[i].controller, SDL_CONTROLLER_BUTTON_BACK); */ process_button(& (old_controller_input->but_u. six_buttons.l_shoulder), &(new_controller_input->but_u. six_buttons.l_shoulder), ctx->players[i].controller, SDL_CONTROLLER_BUTTON_LEFTSHOULDER); process_button(& (old_controller_input->but_u. six_buttons.r_shoulder), &(new_controller_input->but_u. six_buttons.r_shoulder), ctx->players[i].controller, SDL_CONTROLLER_BUTTON_RIGHTSHOULDER); process_button(&(old_controller_input->but_u.six_buttons.down), &(new_controller_input->but_u.six_buttons.down), ctx->players[i].controller, SDL_CONTROLLER_BUTTON_A); process_button(&(old_controller_input->but_u.six_buttons.right), &(new_controller_input->but_u.six_buttons.right), ctx->players[i].controller, SDL_CONTROLLER_BUTTON_B); process_button(&(old_controller_input->but_u.six_buttons.left), &(new_controller_input->but_u.six_buttons.left), ctx->players[i].controller, SDL_CONTROLLER_BUTTON_X); process_button(&(old_controller_input->but_u.six_buttons.up), &(new_controller_input->but_u.six_buttons.up), ctx->players[i].controller, SDL_CONTROLLER_BUTTON_Y); stick_x = SDL_GameControllerGetAxis(ctx->players[i].controller, SDL_CONTROLLER_AXIS_LEFTX); stick_y = SDL_GameControllerGetAxis(ctx->players[i].controller, SDL_CONTROLLER_AXIS_LEFTY); if (stick_x < 0) { new_controller_input->end_x = stick_x / -32768.0f; } else { new_controller_input->end_x = stick_x / -32767.0f; } new_controller_input->min_x = new_controller_input->max_x = new_controller_input->end_x; if (stick_y < 0) { new_controller_input->end_y = stick_y / -32768.0f; } else { new_controller_input->end_y = stick_y / -32767.0f; } new_controller_input->min_y = new_controller_input->max_y = new_controller_input->end_y; } }