Пример #1
0
	bool handle_input_event(input_event eventid, void* eventdata) override
	{
		// Only handle raw input data
		if (!input_enabled() || eventid != INPUT_EVENT_RAWINPUT)
			return FALSE;

		HRAWINPUT rawinputdevice = *static_cast<HRAWINPUT*>(eventdata);

		BYTE small_buffer[4096];
		std::unique_ptr<BYTE[]> larger_buffer;
		LPBYTE data = small_buffer;
		BOOL result;
		UINT size;

		// ignore if not enabled
		if (!input_enabled())
			return FALSE;

		// determine the size of databuffer we need
		if ((*get_rawinput_data)(rawinputdevice, RID_INPUT, nullptr, &size, sizeof(RAWINPUTHEADER)) != 0)
			return FALSE;

		// if necessary, allocate a temporary buffer and fetch the data
		if (size > sizeof(small_buffer))
		{
			larger_buffer = std::make_unique<BYTE[]>(size);
			data = larger_buffer.get();
			if (data == nullptr)
				return FALSE;
		}

		// fetch the data and process the appropriate message types
		result = (*get_rawinput_data)(static_cast<HRAWINPUT>(rawinputdevice), RID_INPUT, data, &size, sizeof(RAWINPUTHEADER));
		if (result)
		{
			std::lock_guard<std::mutex> scope_lock(m_module_lock);

			rawinput_device *devinfo;
			// find the device in the list and update
			for (int i = 0; i < devicelist()->size(); i++)
			{
				devinfo = dynamic_cast<rawinput_device*>(devicelist()->at(i));
				if (devinfo)
				{
					RAWINPUT *input = reinterpret_cast<RAWINPUT*>(data);
					if (input->header.hDevice == devinfo->device_handle())
					{
						devinfo->queue_events(input, 1);
						result = TRUE;
					}
				}
			}
		}

		return result;
	}
Пример #2
0
	bool handle_input_event(input_event eventid, void* eventdata) override
	{
		// Only handle raw input data
		if (!input_enabled() || eventid != INPUT_EVENT_RAWINPUT)
			return false;

		HRAWINPUT rawinputdevice = *static_cast<HRAWINPUT*>(eventdata);

		BYTE small_buffer[4096];
		std::unique_ptr<BYTE[]> larger_buffer;
		LPBYTE data = small_buffer;
		UINT size;

		// ignore if not enabled
		if (!input_enabled())
			return false;

		// determine the size of databuffer we need
		if ((*get_rawinput_data)(rawinputdevice, RID_INPUT, nullptr, &size, sizeof(RAWINPUTHEADER)) != 0)
			return false;

		// if necessary, allocate a temporary buffer and fetch the data
		if (size > sizeof(small_buffer))
		{
			larger_buffer = std::make_unique<BYTE[]>(size);
			data = larger_buffer.get();
			if (data == nullptr)
				return false;
		}

		// fetch the data and process the appropriate message types
		bool result = (*get_rawinput_data)(static_cast<HRAWINPUT>(rawinputdevice), RID_INPUT, data, &size, sizeof(RAWINPUTHEADER));
		if (result)
		{
			std::lock_guard<std::mutex> scope_lock(m_module_lock);

			RAWINPUT *input = reinterpret_cast<RAWINPUT*>(data);

			// find the device in the list and update
			auto target_device = std::find_if(devicelist()->begin(), devicelist()->end(), [input](auto &device)
			{
				auto devinfo = dynamic_cast<rawinput_device*>(device.get());
				return devinfo != nullptr && input->header.hDevice == devinfo->device_handle();
			});

			if (target_device != devicelist()->end())
			{
				static_cast<rawinput_device*>((*target_device).get())->queue_events(input, 1);
				return true;
			}
		}

		return false;
	}
Пример #3
0
	bool handle_input_event(input_event eventid, void *eventdata) override
	{
		if (!input_enabled())
			return false;

		KeyPressEventArgs *args;

		switch (eventid)
		{
			case INPUT_EVENT_KEYDOWN:
			case INPUT_EVENT_KEYUP:
				args = static_cast<KeyPressEventArgs*>(eventdata);
				devicelist()->for_each_device([args](auto device)
				{
					auto keyboard = dynamic_cast<win32_keyboard_device*>(device);
					if (keyboard != nullptr)
						keyboard->queue_events(args, 1);
				});

				return true;

			default:
				return false;
		}
	}
Пример #4
0
	virtual void input_init(running_machine &machine) override
	{
		win32_mouse_device *devinfo;
		int axisnum, butnum;

		if (!input_enabled() || !mouse_enabled())
			return;

		// allocate a device
		devinfo = devicelist()->create_device<win32_mouse_device>(machine, "Win32 Mouse 1", *this);
		if (devinfo == nullptr)
			return;

		// populate the axes
		for (axisnum = 0; axisnum < 2; axisnum++)
		{
			devinfo->device()->add_item(
				default_axis_name[axisnum],
				static_cast<input_item_id>(ITEM_ID_XAXIS + axisnum),
				generic_axis_get_state<LONG>,
				&devinfo->mouse.lX + axisnum);
		}

		// populate the buttons
		for (butnum = 0; butnum < 2; butnum++)
		{
			devinfo->device()->add_item(
				default_button_name(butnum),
				static_cast<input_item_id>(ITEM_ID_BUTTON1 + butnum),
				generic_button_get_state<BYTE>,
				&devinfo->mouse.rgbButtons[butnum]);
		}
	}
Пример #5
0
	bool handle_input_event(input_event eventid, void* eventdata) override
	{
		if (!input_enabled() || !lightgun_enabled() || eventid != INPUT_EVENT_MOUSE_BUTTON)
			return false;

		auto args = static_cast<MouseButtonEventArgs*>(eventdata);
		devicelist()->for_each_device([args](auto device)
		{
			auto lightgun = dynamic_cast<win32_lightgun_device*>(device);
			if (lightgun != nullptr)
				lightgun->queue_events(args, 1);
		});

		return true;
	}