mirror of
https://github.com/RPCSX/rpcsx.git
synced 2026-04-04 14:08:37 +00:00
Qt/input: add shortcut for toggling emulated mouse and keyboard
This commit is contained in:
parent
ff84e7c6e2
commit
ff6a4bb72d
21 changed files with 192 additions and 29 deletions
|
|
@ -60,11 +60,22 @@ void basic_keyboard_handler::SetTargetWindow(QWindow* target)
|
|||
|
||||
bool basic_keyboard_handler::eventFilter(QObject* watched, QEvent* event)
|
||||
{
|
||||
if (!event)
|
||||
if (!event) [[unlikely]]
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (input::g_active_mouse_and_keyboard != input::active_mouse_and_keyboard::emulated)
|
||||
{
|
||||
if (!m_keys_released)
|
||||
{
|
||||
ReleaseAllKeys();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
m_keys_released = false;
|
||||
|
||||
// !m_target is for future proofing when gsrender isn't automatically initialized on load.
|
||||
// !m_target->isVisible() is a hack since currently a guiless application will STILL inititialize a gsrender (providing a valid target)
|
||||
if (!m_target || !m_target->isVisible() || watched == m_target)
|
||||
|
|
@ -97,7 +108,7 @@ bool basic_keyboard_handler::eventFilter(QObject* watched, QEvent* event)
|
|||
|
||||
void basic_keyboard_handler::keyPressEvent(QKeyEvent* keyEvent)
|
||||
{
|
||||
if (!keyEvent)
|
||||
if (!keyEvent) [[unlikely]]
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
|
@ -118,7 +129,7 @@ void basic_keyboard_handler::keyPressEvent(QKeyEvent* keyEvent)
|
|||
|
||||
void basic_keyboard_handler::keyReleaseEvent(QKeyEvent* keyEvent)
|
||||
{
|
||||
if (!keyEvent)
|
||||
if (!keyEvent) [[unlikely]]
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
|
@ -141,7 +152,7 @@ void basic_keyboard_handler::keyReleaseEvent(QKeyEvent* keyEvent)
|
|||
// key() only shows the modifiers and the modified key (e.g. no easy way of knowing that - was pressed in 'SHIFT+-' in order to get _)
|
||||
s32 basic_keyboard_handler::getUnmodifiedKey(QKeyEvent* keyEvent)
|
||||
{
|
||||
if (!keyEvent)
|
||||
if (!keyEvent) [[unlikely]]
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -86,7 +86,12 @@ bool basic_mouse_handler::eventFilter(QObject* target, QEvent* ev)
|
|||
return false;
|
||||
}
|
||||
|
||||
if (!ev)
|
||||
if (!ev) [[unlikely]]
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (input::g_active_mouse_and_keyboard != input::active_mouse_and_keyboard::emulated)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
|
@ -123,7 +128,10 @@ bool basic_mouse_handler::eventFilter(QObject* target, QEvent* ev)
|
|||
|
||||
void basic_mouse_handler::MouseButtonDown(QMouseEvent* event)
|
||||
{
|
||||
if (!event) return;
|
||||
if (!event) [[unlikely]]
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
const int button = event->button();
|
||||
if (const auto it = std::find_if(m_buttons.cbegin(), m_buttons.cend(), [button](const auto& entry){ return entry.second == button; });
|
||||
|
|
@ -135,7 +143,10 @@ void basic_mouse_handler::MouseButtonDown(QMouseEvent* event)
|
|||
|
||||
void basic_mouse_handler::MouseButtonUp(QMouseEvent* event)
|
||||
{
|
||||
if (!event) return;
|
||||
if (!event) [[unlikely]]
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
const int button = event->button();
|
||||
if (const auto it = std::find_if(m_buttons.cbegin(), m_buttons.cend(), [button](const auto& entry){ return entry.second == button; });
|
||||
|
|
@ -147,7 +158,10 @@ void basic_mouse_handler::MouseButtonUp(QMouseEvent* event)
|
|||
|
||||
void basic_mouse_handler::MouseScroll(QWheelEvent* event)
|
||||
{
|
||||
if (!event) return;
|
||||
if (!event) [[unlikely]]
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
const QPoint delta = event->angleDelta();
|
||||
const s8 x = std::clamp(delta.x() / 120, -128, 127);
|
||||
|
|
@ -177,7 +191,10 @@ int basic_mouse_handler::get_mouse_button(const cfg::string& button)
|
|||
|
||||
void basic_mouse_handler::MouseMove(QMouseEvent* event)
|
||||
{
|
||||
if (!event) return;
|
||||
if (!event) [[unlikely]]
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (is_time_for_update())
|
||||
{
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@
|
|||
#include "pad_thread.h"
|
||||
#include "Emu/Io/pad_config.h"
|
||||
#include "Emu/Io/KeyboardHandler.h"
|
||||
#include "Emu/Io/interception.h"
|
||||
#include "Input/product_info.h"
|
||||
#include "rpcs3qt/gs_frame.h"
|
||||
|
||||
|
|
@ -324,10 +325,28 @@ void keyboard_pad_handler::release_all_keys()
|
|||
pad.m_sticks[i].m_value = 128;
|
||||
}
|
||||
}
|
||||
|
||||
m_keys_released = true;
|
||||
}
|
||||
|
||||
bool keyboard_pad_handler::eventFilter(QObject* target, QEvent* ev)
|
||||
{
|
||||
if (!ev) [[unlikely]]
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (input::g_active_mouse_and_keyboard != input::active_mouse_and_keyboard::pad)
|
||||
{
|
||||
if (!m_keys_released)
|
||||
{
|
||||
release_all_keys();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
m_keys_released = false;
|
||||
|
||||
// !m_target is for future proofing when gsrender isn't automatically initialized on load.
|
||||
// !m_target->isVisible() is a hack since currently a guiless application will STILL inititialize a gsrender (providing a valid target)
|
||||
if (!m_target || !m_target->isVisible()|| target == m_target)
|
||||
|
|
@ -381,6 +400,11 @@ void keyboard_pad_handler::SetTargetWindow(QWindow* target)
|
|||
|
||||
void keyboard_pad_handler::processKeyEvent(QKeyEvent* event, bool pressed)
|
||||
{
|
||||
if (!event) [[unlikely]]
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (event->isAutoRepeat())
|
||||
{
|
||||
event->ignore();
|
||||
|
|
@ -444,6 +468,11 @@ void keyboard_pad_handler::processKeyEvent(QKeyEvent* event, bool pressed)
|
|||
|
||||
void keyboard_pad_handler::keyPressEvent(QKeyEvent* event)
|
||||
{
|
||||
if (!event) [[unlikely]]
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (event->modifiers() & Qt::AltModifier)
|
||||
{
|
||||
switch (event->key())
|
||||
|
|
@ -502,12 +531,22 @@ void keyboard_pad_handler::keyReleaseEvent(QKeyEvent* event)
|
|||
|
||||
void keyboard_pad_handler::mousePressEvent(QMouseEvent* event)
|
||||
{
|
||||
if (!event) [[unlikely]]
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Key(event->button(), true);
|
||||
event->ignore();
|
||||
}
|
||||
|
||||
void keyboard_pad_handler::mouseReleaseEvent(QMouseEvent* event)
|
||||
{
|
||||
if (!event) [[unlikely]]
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Key(event->button(), false, 0);
|
||||
event->ignore();
|
||||
}
|
||||
|
|
@ -521,7 +560,7 @@ bool keyboard_pad_handler::get_mouse_lock_state() const
|
|||
|
||||
void keyboard_pad_handler::mouseMoveEvent(QMouseEvent* event)
|
||||
{
|
||||
if (!m_mouse_move_used)
|
||||
if (!m_mouse_move_used || !event)
|
||||
{
|
||||
event->ignore();
|
||||
return;
|
||||
|
|
@ -659,7 +698,7 @@ void keyboard_pad_handler::mouseMoveEvent(QMouseEvent* event)
|
|||
|
||||
void keyboard_pad_handler::mouseWheelEvent(QWheelEvent* event)
|
||||
{
|
||||
if (!m_mouse_wheel_used)
|
||||
if (!m_mouse_wheel_used || !event)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -105,6 +105,7 @@ protected:
|
|||
private:
|
||||
QWindow* m_target = nullptr;
|
||||
mouse_movement_mode m_mouse_movement_mode = mouse_movement_mode::relative;
|
||||
bool m_keys_released = false;
|
||||
bool m_mouse_move_used = false;
|
||||
bool m_mouse_wheel_used = false;
|
||||
bool get_mouse_lock_state() const;
|
||||
|
|
|
|||
|
|
@ -16,6 +16,7 @@
|
|||
#endif
|
||||
#include "keyboard_pad_handler.h"
|
||||
#include "Emu/Io/Null/NullPadHandler.h"
|
||||
#include "Emu/Io/interception.h"
|
||||
#include "Emu/Io/PadHandler.h"
|
||||
#include "Emu/Io/pad_config.h"
|
||||
#include "Emu/System.h"
|
||||
|
|
@ -200,6 +201,9 @@ void pad_thread::Init()
|
|||
|| (pad->m_class_type >= CELL_PAD_FAKE_TYPE_FIRST && pad->m_class_type < CELL_PAD_FAKE_TYPE_LAST);
|
||||
connect_usb_controller(i, input::get_product_by_vid_pid(pad->m_vendor_id, pad->m_product_id));
|
||||
}
|
||||
|
||||
// Initialize active mouse and keyboard. Activate pad handler if one exists.
|
||||
input::set_mouse_and_keyboard(m_handlers.contains(pad_handler::keyboard) ? input::active_mouse_and_keyboard::pad : input::active_mouse_and_keyboard::emulated);
|
||||
}
|
||||
|
||||
void pad_thread::SetRumble(const u32 pad, u8 large_motor, bool small_motor)
|
||||
|
|
|
|||
|
|
@ -432,7 +432,7 @@ void raw_mouse_handler::register_raw_input_devices()
|
|||
m_registered_raw_input_devices = true;
|
||||
}
|
||||
|
||||
void raw_mouse_handler::unregister_raw_input_devices()
|
||||
void raw_mouse_handler::unregister_raw_input_devices() const
|
||||
{
|
||||
if (!m_registered_raw_input_devices)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -108,7 +108,7 @@ private:
|
|||
|
||||
#ifdef _WIN32
|
||||
void register_raw_input_devices();
|
||||
void unregister_raw_input_devices();
|
||||
void unregister_raw_input_devices() const;
|
||||
bool m_registered_raw_input_devices = false;
|
||||
#endif
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue