2025-08-20 23:06:28 +08:00
|
|
|
|
#ifndef CURSORCONTROLLER_H
|
|
|
|
|
|
#define CURSORCONTROLLER_H
|
|
|
|
|
|
|
|
|
|
|
|
#include <QObject>
|
|
|
|
|
|
#include <QPoint>
|
|
|
|
|
|
#include <QKeyEvent>
|
2025-09-15 22:28:43 +08:00
|
|
|
|
#include <QTimer>
|
2025-08-20 23:06:28 +08:00
|
|
|
|
class CursorController : public QObject
|
|
|
|
|
|
{
|
|
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
public:
|
|
|
|
|
|
explicit CursorController(QObject *parent = nullptr);
|
|
|
|
|
|
|
|
|
|
|
|
// 可调参数
|
|
|
|
|
|
struct Config {
|
|
|
|
|
|
int step = 20; // 每步像素
|
|
|
|
|
|
bool wrap = false;// 边缘回绕
|
|
|
|
|
|
bool emulate = true; // 是否发送点击事件
|
|
|
|
|
|
int edgeGap = 5; // 离边缘空隙
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
Config cfg; // 直接改成员即可实时生效
|
|
|
|
|
|
|
|
|
|
|
|
public slots:
|
|
|
|
|
|
void handleKey(int key); // 接受 Qt::Key_xxx
|
2025-09-15 22:28:43 +08:00
|
|
|
|
void handleKey(int key, bool pressed);
|
2025-08-20 23:06:28 +08:00
|
|
|
|
signals:
|
|
|
|
|
|
void cursorMoved(const QPoint &globalPos);
|
|
|
|
|
|
void clicked(QWidget *target);
|
|
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
QPoint m_pos;
|
|
|
|
|
|
bool m_useRealCursor; // true: 系统光标 false: 自绘光标
|
|
|
|
|
|
void move(const QPoint &delta);
|
|
|
|
|
|
void emulateClick();
|
2025-09-15 22:28:43 +08:00
|
|
|
|
|
|
|
|
|
|
QTimer m_holdTimer; // 用来检测是否达到长按时间
|
|
|
|
|
|
bool m_isLongPress; // 当前按键是否是长按
|
|
|
|
|
|
int m_curStep; // 当前应该用的步长(1 或 5)
|
2025-08-20 23:06:28 +08:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
#endif // CURSORCONTROLLER_H
|