Exemplo n.º 1
0
/**
 * @brief Returns the direction that was pressed or released
 * during this keyboard or joypad event.
 *
 * If this is not a keyboard or joypad event, or if
 * the control was not a direction, -1 is returned.
 *
 * @return the direction (0 to 7) or -1 if there is no direction
 */
int InputEvent::get_direction() {

  int result = -1;

  if (is_keyboard_direction_key_pressed()) {
    
    switch (get_keyboard_key()) {

      case KEY_RIGHT:
	result = 0;
	break;

      case KEY_UP:
	result = 2;
	break;

      case KEY_LEFT:
	result = 4;
	break;

      case KEY_DOWN:
	result = 6;
	break;

      default:
	break;
    }
  }
  else if (is_joypad_axis_moved() && !is_joypad_axis_centered()) {

    if (get_joypad_axis() % 2 == 0) {
      // we assume the axis is horizontal
      result = (get_joypad_axis_state() > 0) ? 0 : 4;
    }
    else {
      // we assume the axis is vertical
      result = (get_joypad_axis_state() > 0) ? 6 : 2;
    }
  }
  else if (is_joypad_hat_moved()) {
    result = get_joypad_hat_direction(); 
  }

  return result;
}
Exemplo n.º 2
0
void AnalyzeKeyEvent(int pad, keyEvent &evt)
{
	KeySym key = (KeySym)evt.key;
	int index = get_keyboard_key(pad, key);

	switch (evt.evt)
	{
		case KeyPress:
			// Shift F12 is not yet use by pcsx2. So keep it to grab/ungrab input
			// I found it very handy vs the automatic fullscreen detection
			// 1/ Does not need to detect full-screen
			// 2/ Can use a debugger in full-screen
			// 3/ Can grab input in window without the need of a pixelated full-screen
			if (key == XK_Shift_R || key == XK_Shift_L) s_Shift = true;
			if (key == XK_F12 && s_Shift) {
				if(!s_grab_input) {
					s_grab_input = true;
					XGrabPointer(GSdsp, GSwin, True, ButtonPressMask, GrabModeAsync, GrabModeAsync, GSwin, None, CurrentTime);
					XGrabKeyboard(GSdsp, GSwin, True, GrabModeAsync, GrabModeAsync, CurrentTime);
				} else {
					s_grab_input = false;
					XUngrabPointer(GSdsp, CurrentTime);
					XUngrabKeyboard(GSdsp, CurrentTime);
				}
			}

			// Analog controls.
			if (IsAnalogKey(index))
			{
				switch (index)
				{
					case PAD_R_LEFT:
					case PAD_R_UP:
					case PAD_L_LEFT:
					case PAD_L_UP:
						key_status->press(pad, index, -MAX_ANALOG_VALUE);
						break;
					case PAD_R_RIGHT:
					case PAD_R_DOWN:
					case PAD_L_RIGHT:
					case PAD_L_DOWN:
						key_status->press(pad, index, MAX_ANALOG_VALUE);
						break;
				}
			} else if (index != -1)
				key_status->press(pad, index);

			//PAD_LOG("Key pressed:%d\n", index);

			event.evt = KEYPRESS;
			event.key = key;
			break;

		case KeyRelease:
			if (key == XK_Shift_R || key == XK_Shift_L) s_Shift = false;

			if (index != -1)
				key_status->release(pad, index);

			event.evt = KEYRELEASE;
			event.key = key;
			break;

		case FocusIn:
			//XAutoRepeatOff(GSdsp);
			break;

		case FocusOut:
			//XAutoRepeatOn(GSdsp);
			s_Shift = false;
			break;

		case ButtonPress:
			if (index != -1)
				key_status->press(pad, index);
			break;

		case ButtonRelease:
			if (index != -1)
				key_status->release(pad, index);
			break;

		case MotionNotify:
			// FIXME: How to handle when the mouse does not move, no event generated!!!
			// 1/ small move == no move. Cons : can not do small movement
			// 2/ use a watchdog timer thread
			// 3/ ??? idea welcome ;)
			if (conf->pad_options[pad].mouse_l|conf->pad_options[pad].mouse_r)  {
				unsigned int pad_x;
				unsigned int pad_y;
				// Note when both PADOPTION_MOUSE_R and PADOPTION_MOUSE_L are set, take only the right one
				if (conf->pad_options[pad].mouse_r) {
					pad_x = PAD_R_RIGHT;
					pad_y = PAD_R_UP;
				} else {
					pad_x = PAD_L_RIGHT;
					pad_y = PAD_L_UP;
				}

				unsigned x = evt.key & 0xFFFF;
				unsigned int value = (s_previous_mouse_x > x) ? s_previous_mouse_x - x : x - s_previous_mouse_x;
				value *= conf->get_sensibility();

				if (x == 0)
					key_status->press(pad, pad_x, -MAX_ANALOG_VALUE);
				else if (x == 0xFFFF)
					key_status->press(pad, pad_x, MAX_ANALOG_VALUE);
				else if (x < (s_previous_mouse_x -2))
					key_status->press(pad, pad_x, -value);
				else if (x > (s_previous_mouse_x +2))
					key_status->press(pad, pad_x, value);
				else
					key_status->release(pad, pad_x);


				unsigned y = evt.key >> 16;
				value = (s_previous_mouse_y > y) ? s_previous_mouse_y - y : y - s_previous_mouse_y;
				value *= conf->get_sensibility();

				if (y == 0)
					key_status->press(pad, pad_y, -MAX_ANALOG_VALUE);
				else if (y == 0xFFFF)
					key_status->press(pad, pad_y, MAX_ANALOG_VALUE);
				else if (y < (s_previous_mouse_y -2))
					key_status->press(pad, pad_y, -value);
				else if (y > (s_previous_mouse_y +2))
					key_status->press(pad, pad_y, value);
				else
					key_status->release(pad, pad_y);

				s_previous_mouse_x = x;
				s_previous_mouse_y = y;
			}

			break;
	}
Exemplo n.º 3
0
/**
 * @brief Returns whether this event is a keyboard event
 * corresponding to releasing a specific key.
 * @param key the key to test
 * @return true if this event corresponds to releasing that key
 */
bool InputEvent::is_keyboard_key_released(KeyboardKey key) {

  return is_keyboard_key_released()
    && get_keyboard_key() == key;
}
Exemplo n.º 4
0
/**
 * \brief Returns whether this event is a keyboard event
 * corresponding to pressing a specific key.
 * \param key the key to test
 * \return true if this event corresponds to pressing that key
 */
bool InputEvent::is_keyboard_key_pressed(KeyboardKey key) const {

  return is_keyboard_key_pressed()
    && get_keyboard_key() == key;
}