Пример #1
0
	InputDevice InputDevice::getDevice(int id)
	{
		InputDevice retVal = InputDevice(0);
		if (!_env)
		{
			__android_log_print(ANDROID_LOG_ERROR, LOG_TAG, "JNI must be initialized with a valid environment!");
			return retVal;
		}

		jint arg1 = id;
		jobject result = _env->CallStaticObjectMethod(_jcInputDevice, _mGetDevice, arg1);
		if (_env->ExceptionCheck())
		{
			_env->ExceptionDescribe();
			_env->ExceptionClear();
			__android_log_print(ANDROID_LOG_ERROR, LOG_TAG, "Failed to get device");
			return retVal;
		}
		if (result)
		{
			__android_log_print(ANDROID_LOG_VERBOSE, LOG_TAG, "Success get device");
			retVal = InputDevice(result);
			return retVal;
		}
		else
		{
			__android_log_print(ANDROID_LOG_ERROR, LOG_TAG, "Failed get device");
			return retVal;
		}
	}
Пример #2
0
static BOOL CALLBACK EnumDevices( const DIDEVICEINSTANCE *pdidInstance, void *pContext )
{
	DIDevice device;

	switch( pdidInstance->dwDevType & 0xFF )
	{
	case DIDEVTYPE_KEYBOARD: device.type = device.KEYBOARD; break;
	case DIDEVTYPE_JOYSTICK: device.type = device.JOYSTICK; break;
	default: return DIENUM_CONTINUE;
	}

	device.JoystickInst = *pdidInstance;

	switch( device.type )
	{
	case device.JOYSTICK:
		if( g_NumJoysticks == NUM_JOYSTICKS )
			return DIENUM_CONTINUE;

		device.dev = InputDevice( DEVICE_JOY1 + g_NumJoysticks );
		g_NumJoysticks++;
		break;

	case device.KEYBOARD:
		device.dev = InputDevice( DEVICE_KEYBOARD );
		break;
	}

	Devices.push_back(device);

	return DIENUM_CONTINUE;
}
Пример #3
0
void InputHandler_SDL::Update(float fDeltaTime)
{
	SDL_Event event;
	while(SDL_GetEvent(event, SDL_EventMask2))
	{
		switch(event.type)
		{
		case SDL_KEYDOWN:
		case SDL_KEYUP:
			{
			LOG->Trace("key: sym %i, key %i, state %i",
				event.key.keysym.sym, SDLSymToKeySym(event.key.keysym.sym), event.key.state );
			DeviceInput di( DEVICE_KEYBOARD, SDLSymToKeySym(event.key.keysym.sym) );
			ButtonPressed(di, event.key.state == SDL_PRESSED);
			}
			continue;

		case SDL_JOYBUTTONDOWN:
		case SDL_JOYBUTTONUP:
		{
			InputDevice i = InputDevice(DEVICE_JOY1 + event.jbutton.which);
			JoystickButton Button = JoystickButton(JOY_1 + event.jbutton.button);
			if(Button >= NUM_JOYSTICK_BUTTONS)
			{
				LOG->Warn("Ignored joystick event (button too high)");
				continue;
			}
			DeviceInput di(i, Button);
			ButtonPressed(di, event.jbutton.state == SDL_PRESSED);
			continue;
		}
		
		case SDL_JOYAXISMOTION:
		{
			InputDevice i = InputDevice(DEVICE_JOY1 + event.jaxis.which);
			JoystickButton neg = (JoystickButton)(JOY_LEFT+2*event.jaxis.axis);
			JoystickButton pos = (JoystickButton)(JOY_RIGHT+2*event.jaxis.axis);
			float l = SCALE( event.jaxis.value, 0.0f, 32768.0f, 0.0f, 1.0f );
			ButtonPressed(DeviceInput(i, neg,max(-l,0),RageZeroTimer), event.jaxis.value < -16000);
			ButtonPressed(DeviceInput(i, pos,max(+l,0),RageZeroTimer), event.jaxis.value > +16000);
			continue;
		}
		
		case SDL_JOYHATMOTION:
		{
			InputDevice i = InputDevice(DEVICE_JOY1 + event.jhat.which);
			ButtonPressed(DeviceInput(i, JOY_HAT_UP), !!(event.jhat.value & SDL_HAT_UP));
			ButtonPressed(DeviceInput(i, JOY_HAT_DOWN), !!(event.jhat.value & SDL_HAT_DOWN));
			ButtonPressed(DeviceInput(i, JOY_HAT_LEFT), !!(event.jhat.value & SDL_HAT_LEFT));
			ButtonPressed(DeviceInput(i, JOY_HAT_RIGHT), !!(event.jhat.value & SDL_HAT_RIGHT));
			continue;
		}
		}
	}

	InputHandler::UpdateTimer();
}
Пример #4
0
	X11Window::X11Window()
	: handle(), color_map(0), system_cursor(0), hidden_cursor(0), cursor_bitmap(0), size_hints(nullptr),
	  minimized(false), maximized(false), restore_to_maximized(false), fullscreen(false),
	  is_window_mapped(false),
	  site(nullptr), clipboard(this)
	{
		handle.display = SetupDisplay::get_message_queue()->get_display();
		keyboard = InputDevice(new InputDeviceProvider_X11Keyboard(this));
		mouse = InputDevice(new InputDeviceProvider_X11Mouse(this));

		SetupDisplay::get_message_queue()->add_client(this);
	}
void InputHandler_Win32_Pump::GetDevicesAndDescriptions( vector<InputDeviceInfo>& vDevicesOut )
{
	for(int i = 0; i < NUM_PUMPS; ++i)
	{
		if( m_pDevice[i].IsOpen() )
		{
			vDevicesOut.push_back( InputDeviceInfo(InputDevice(DEVICE_PUMP1+i),"Pump USB") );
		}
	}
}
void InputHandler_Linux_Joystick::GetDevicesAndDescriptions( vector<InputDevice>& vDevicesOut, vector<CString>& vDescriptionsOut )
{
	for (int i = 0; i < NUM_JOYSTICKS; i++)
	{
		if (m_Devs[i].fd < 0)
			continue;

		vDevicesOut.push_back( InputDevice(DEVICE_JOY1+i) );
		vDescriptionsOut.push_back( m_Devs[i].name );
	}
}
Пример #7
0
InputDevice* InputDeviceManager::createInputDevice(const char* deviceName,int trackType,int numButtons,int numValuators,bool physicalDevice)
	{
	/* Get the length of the given device name's prefix: */
	int deviceNamePrefixLength=getPrefixLength(deviceName);
		
	/* Check if a device of the same name prefix already exists: */
	bool exists=false;
	int maxAliasIndex=0;
	for(InputDevices::iterator devIt=inputDevices.begin();devIt!=inputDevices.end();++devIt)
		{
		/* Compare the two prefixes: */
		if(getPrefixLength(devIt->getDeviceName())==deviceNamePrefixLength&&strncmp(deviceName,devIt->getDeviceName(),deviceNamePrefixLength)==0)
			{
			exists=true;
			if(devIt->getDeviceName()[deviceNamePrefixLength]==':')
				{
				int aliasIndex=atoi(devIt->getDeviceName()+deviceNamePrefixLength);
				if(maxAliasIndex<aliasIndex)
					maxAliasIndex=aliasIndex;
				}
			}
		}
	
	/* Create a new (uninitialized) input device: */
	InputDevices::iterator newDevice=inputDevices.insert(inputDevices.end(),InputDevice());
	InputDevice* newDevicePtr=&(*newDevice); // This looks iffy, but I don't know of a better way
	
	/* Initialize the new input device: */
	if(exists)
		{
		/* Create a new alias name for the new device: */
		char newDeviceNameBuffer[256];
		strncpy(newDeviceNameBuffer,deviceName,deviceNamePrefixLength);
		snprintf(newDeviceNameBuffer+deviceNamePrefixLength,sizeof(newDeviceNameBuffer)-deviceNamePrefixLength,":%d",maxAliasIndex+1);
		newDevicePtr->set(newDeviceNameBuffer,trackType,numButtons,numValuators);
		}
	else
		newDevicePtr->set(deviceName,trackType,numButtons,numValuators);
	
	/* Add the new input device to the input graph: */
	inputGraphManager->addInputDevice(newDevicePtr);
	
	/* If it's a physical device, grab it permanently: */
	if(physicalDevice)
		inputGraphManager->grabInputDevice(newDevicePtr,0); // Passing in null as grabber grabs for the physical layer
	
	/* Call the input device creation callbacks: */
	InputDeviceCreationCallbackData cbData(this,newDevicePtr);
	inputDeviceCreationCallbacks.call(&cbData);
	
	/* Return a pointer to the new input device: */
	return newDevicePtr;
	}
Пример #8
0
void InputHandler_SDL::GetDevicesAndDescriptions(vector<InputDevice>& vDevicesOut, vector<CString>& vDescriptionsOut)
{
	vDevicesOut.push_back( DEVICE_KEYBOARD );
	vDescriptionsOut.push_back( "Keyboard" );

	for( int i=0; i<SDL_NumJoysticks(); i++ )
	{
		if( SDL_JoystickOpened(i) )
		{
			vDevicesOut.push_back( InputDevice(DEVICE_JOY1+i) );
			vDescriptionsOut.push_back( SDL_JoystickName(i) );
		}
	}
}
Пример #9
0
void InputContext_Impl::process_messages()
{
	throw_if_disposed();

	std::vector< std::pair<InputEvent, std::weak_ptr<InputDevice_Impl> > >::size_type pos, size;

	// Fetch latest events received:
	std::unique_lock<std::recursive_mutex> mutex_lock(mutex);
	std::vector< std::pair<InputEvent, std::weak_ptr<InputDevice_Impl> > > cur_events  = events;
	events.clear();
	mutex_lock.unlock();

	size = cur_events.size();
	for (pos = 0; pos < size; pos++)
	{
		if (is_disposed())	// Exit the function now if a previous input event has caused the input context to be disposed
			break;

		InputEvent event = cur_events[pos].first;
		if (cur_events[pos].second.expired())
			continue;
		event.device = InputDevice(cur_events[pos].second);

		switch (event.type)
		{
		case InputEvent::pressed:
			event.device.sig_key_down()(event);
			break;
		case InputEvent::released:
			event.device.sig_key_up()(event);
			break;
		case InputEvent::doubleclick:
			event.device.sig_key_dblclk()(event);
			break;
		case InputEvent::pointer_moved:
			event.device.sig_pointer_move()(event);
			break;
		case InputEvent::axis_moved:
			event.device.sig_axis_move()(event);
			break;
		case InputEvent::proximity_change:
			event.device.sig_proximity_change()(event);
			break;
		default:	// Added to stop the compiler warning about "no_key" not handled in switch
			break;
		}
	}
}
Пример #10
0
	wxString BoxClass::TowxString() const {
		wxString routeString;
		for (routeListType::const_iterator r = routes.begin();
		     r != routes.end(); r++)
			routeString += wxString::Format(_T(" %d:(%d->%d->%d)"),
							(*r)->get_routefile_id(),
							(*r)->GetDeviceId(InputDevice()),
							(*r)->GetBoxId(),
							(*r)->GetDeviceId(OutputDevice()));


		return wxString::Format(_T("\nBox:\n\
   session_id    = %lu\n\
   routefile_id  = %d\n\
   routes: %s\n"),
					(unsigned long)session_id(),
					routefile_id,routeString.c_str());
	}
Пример #11
0
void InputHandler_Win32_Pump::HandleInput( int iDevice, int iEvent )
{
	static const int bits[NUM_PUMP_PAD_BUTTONS] = {
	/* P1 */	(1<<9), (1<<12), (1<<13), (1<<11), (1<<10),
	/* ESC */	(1<<16),
	/* P1 */	(1<<17), (1<<20), (1<<21), (1<<19), (1<<18),
	};

	InputDevice id = InputDevice( DEVICE_PUMP1 + iDevice );

	for( int iButton = 0; iButton < NUM_PUMP_PAD_BUTTONS; ++iButton )
	{
		DeviceInput di( id, iButton );
		
		/* If we're in a thread, our timestamp is accurate. */
		if( InputThread.IsCreated() )
			di.ts.Touch();

		ButtonPressed( di, !(iEvent & bits[iButton]) );
	}
}
Пример #12
0
void InputFilter::Reset()
{
	for( int i=0; i<NUM_INPUT_DEVICES; i++ )
		ResetDevice( InputDevice(i) );
}
Пример #13
0
void InputHandler_MonkeyKeyboard::GetDevicesAndDescriptions(vector<InputDevice>& vDevicesOut, vector<CString>& vDescriptionsOut)
{
	vDevicesOut.push_back( InputDevice(DEVICE_KEYBOARD) );
	vDescriptionsOut.push_back( "MonkeyKeyboard" );
}
Пример #14
0
void InputHandler_Linux_Joystick::InputThread()
{
	while( !m_bShutdown )
	{
		m_DebugTimer.StartUpdate();

		fd_set fdset;
		FD_ZERO(&fdset);
		int max_fd = -1;
		
		for(int i = 0; i < NUM_JOYSTICKS; ++i)
		{
			if (m_Devs[i].fd < 0)
				continue;

			FD_SET(m_Devs[i].fd, &fdset);
			max_fd = max(max_fd, m_Devs[i].fd);
		}

		struct timeval zero = {0,100000};
		if( select(max_fd+1, &fdset, NULL, NULL, &zero) <= 0 )
			continue;

		for(int i = 0; i < NUM_JOYSTICKS; ++i)
		{
			if (m_Devs[i].fd < 0)
				continue;

			if(!FD_ISSET(m_Devs[i].fd, &fdset))
				continue;

			js_event event;
			int ret = read(m_Devs[i].fd, &event, sizeof(event));
			if(ret != sizeof(event))
			{
				LOG->Warn("Unexpected packet (size %i != %i) from joystick %i; disabled", ret, (int)sizeof(event), i);
				Detach(m_Devs[i].path);
				continue;
			}

			InputDevice id = InputDevice(DEVICE_JOY1 + i);
			DeviceInput di = DeviceInput( id, JOY_1 );

			event.type &= ~JS_EVENT_INIT;
			switch (event.type) {
			case JS_EVENT_BUTTON: {
				int iNum = event.number;
				// In 2.6.11 using an EMS USB2, the event number for P1 Tri (the first button)
				// is being reported as 32 instead of 0.  Correct for this.
				wrap( iNum, 32 );	// max number of joystick buttons.  Make this a constant?

				// set the DeviceInput timestamp and button
				di.button = JOY_1 + iNum;
				di.ts.Touch();
				ButtonPressed( di, event.value );
				break;
			}
				
			case JS_EVENT_AXIS: {
				DeviceButton neg = (JoystickButton)(JOY_LEFT+2*event.number);
				DeviceButton pos = (JoystickButton)(JOY_RIGHT+2*event.number);

				di.ts.Touch();
				di.button = neg; ButtonPressed( di, event.value < -16000 );
				di.button = pos; ButtonPressed( di, event.value > +16000 );
				break;
			}
				
			default:
				LOG->Warn("Unexpected packet (type %i) from joystick %i; disabled", event.type, i);
				Detach(m_Devs[i].path);
				continue;
			}

		}

		InputHandler::UpdateTimer();

		m_DebugTimer.EndUpdate();
	}
}
Пример #15
0
void InputFilter::Reset()
{
    FOREACH_InputDevice( i )
    ResetDevice( InputDevice(i) );
}
Пример #16
0
namespace Input
{

std::array<InputDevice, MAX_PLAYER> InputDevice::DeviceList = 
{
    InputDevice("Player 1"), 
    InputDevice("Player 2"), 
    InputDevice("Player 3"), 
    InputDevice("Player 4")
};

InputDevice::InputDevice(const std::string &name) :
    _name(name),
    _keyMap(),
    _type(InputDeviceType::UNKNOWN)
{
    _keyMap.fill(SDLK_UNKNOWN);

    //TODO: only support keyboard for now
    _type = InputDevice::InputDeviceType::KEYBOARD;
}

bool InputDevice::isButtonPressed(const InputButton button) const
{
    if(button == InputButton::COUNT) {
        return false;
    }

    const SDL_Scancode code = SDL_GetScancodeFromKey(_keyMap[static_cast<size_t>(button)]);

    return SDL_GetKeyboardState(nullptr)[code];
}

void InputDevice::setInputMapping(const InputButton button, const SDL_Keycode key)
{
    if(button != InputButton::COUNT) {
        _keyMap[static_cast<size_t>(button)] = key;
    }
}

std::string InputDevice::getMappedInputName(const InputButton button) const
{
    SDL_Keycode key = SDLK_UNKNOWN;

    if(button != InputButton::COUNT) {
        key = _keyMap[static_cast<size_t>(button)];
    }

    if(key == SDLK_UNKNOWN) {
        return "SDLK_UNKNOWN";
    }

    return SDL_GetKeyName(key);
}

InputDevice::InputDeviceType InputDevice::getDeviceType() const
{
    return _type;
}

Vector2f InputDevice::getInputMovement() const
{
    Vector2f result = Vector2f::zero();

    switch(_type)
    {
        // Keyboard routines
        case Ego::Input::InputDevice::InputDeviceType::KEYBOARD:
        {
            if(isButtonPressed(Ego::Input::InputDevice::InputButton::MOVE_RIGHT)) {
                result.x()++;
            }   
            if(isButtonPressed(Ego::Input::InputDevice::InputButton::MOVE_LEFT)) {
                result.x()--;
            }
            if(isButtonPressed(Ego::Input::InputDevice::InputButton::MOVE_DOWN)) {
                result.y()++;
            }   
            if(isButtonPressed(Ego::Input::InputDevice::InputButton::MOVE_UP)) {
                result.y()--;
            }
        }
        break;

        // Mouse routines
        case Ego::Input::InputDevice::InputDeviceType::MOUSE:
        {
            const float dist = InputSystem::get().getMouseMovement().length();
            if (dist > 0)
            {
                float scale = InputSystem::MOUSE_SENSITIVITY / dist;
                if (dist < InputSystem::MOUSE_SENSITIVITY)
                {
                    scale = dist / InputSystem::MOUSE_SENSITIVITY;
                }

                if (InputSystem::MOUSE_SENSITIVITY > 0.0f)
                {
                    scale /= InputSystem::MOUSE_SENSITIVITY;
                }

                result = InputSystem::get().getMouseMovement() * scale;
            }
        }
        break;

        case Ego::Input::InputDevice::InputDeviceType::JOYSTICK:
        {
            //TODO: Not implemented
            /*
            //Figure out which joystick we are using
            joystick_data_t *joystick;
            joystick = InputSystem::get().joysticks[pdevice->device_type - MAX_JOYSTICK].get();

            if ( fast_camera_turn || !input_device_t::control_active( pdevice, CONTROL_CAMERA ) )
            {
                joy_pos[XX] = joystick->x;
                joy_pos[YY] = joystick->y;

                float dist = joy_pos.length_2();
                if ( dist > 1.0f )
                {
                    scale = 1.0f / std::sqrt( dist );
                    joy_pos *= scale;
                }

                if ( fast_camera_turn && !input_device_t::control_active( pdevice, CONTROL_CAMERA ) )  joy_pos[XX] = 0;

                movementInput.x() = ( joy_pos[XX] * fcos + joy_pos[YY] * fsin );
                movementInput.y() = ( -joy_pos[XX] * fsin + joy_pos[YY] * fcos );
            }
            */
        }
        break;

        case Ego::Input::InputDevice::InputDeviceType::UNKNOWN:
            //Should not happen... throw exception?
        break;
    }

    return result;
}

} //Input