Skip to content

Commit

Permalink
fixed an issue where the recovery mouse cursor position feature
Browse files Browse the repository at this point in the history
  • Loading branch information
opiopan committed Nov 30, 2024
1 parent cdab1af commit 347531d
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 19 deletions.
2 changes: 1 addition & 1 deletion src/core/fs2020.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ class FS2020 : public SimHostManager::Simulator{
void initLuaEnv(sol::state& lua) override;
void changeActivity(bool isActive) override;
HWND getRepresentativeWindow() override{return representativeWindow;}
mouse_emu::recovery_type getRecoveryType() override{return mouse_emu::recovery_type::left;}
mouse_emu::recovery_type getRecoveryType() override{return mouse_emu::recovery_type::right;}

void updateMfwasm();
template <typename FUNC>
Expand Down
44 changes: 26 additions & 18 deletions src/hook/hookdll.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -296,8 +296,7 @@ class LeadManager : public Manager{
return true;
};

bool setWinodForRecovery(HWND hwnd, int type){
LockHolder lock(mutex);
void setWinodForRecovery(HWND hwnd, int type){
::SendMessageW(hwnd, controlMessage, static_cast<DWORD>(ControllMessageDword::set_window_for_recovery), type);
}
};
Expand Down Expand Up @@ -331,6 +330,8 @@ class FollowingManager : public Manager{
int acceptable_delta = 5;
mouse_emu::clock::time_point last_ops_time = mouse_emu::clock::now();
mouse_emu::clock::time_point last_down_time = mouse_emu::clock::now();
bool is_touch_down{false};
POINT last_touch_point;
};
struct ChangeRequest{
bool change_position:1;
Expand All @@ -347,8 +348,8 @@ class FollowingManager : public Manager{
int64_t local_count = 0;
std::map<HWND, WindowContext> captured_windows;
std::unique_ptr<mouse_emu::emulator> mouse_emulator;
bool is_touch_down{false};
POINT last_touch_point;
HWND window_for_recovery{0};
mouse_emu::recovery_type recovery_type{mouse_emu::recovery_type::none};

HookedApi<LONG_PTR WINAPI (HWND, int, LONG_PTR)> SetWindowLongPtrW;
HookedApi<BOOL WINAPI (HWND, HWND, int, int, int, int, UINT)> SetWindowPos;
Expand Down Expand Up @@ -406,12 +407,13 @@ class FollowingManager : public Manager{
ctx.need_to_modify_touch = true;
RegisterTouchWindow(hWnd, 0);
}
captured_windows.emplace(hWnd, ctx);
llock.unlock();
glock.unlock();
if (ctx.need_to_modify_touch && !mouse_emulator){
mouse_emulator = std::move(mouse_emu::create_emulator());
mouse_emulator->set_window_for_recovery(window_for_recovery, recovery_type);
}
captured_windows.emplace(hWnd, ctx);
llock.unlock();
glock.unlock();
if (option & CAPTURE_OPT_HIDE_SYSTEM_REGION){
this->SetWindowLongPtrW(
hWnd, GWL_STYLE,
Expand Down Expand Up @@ -520,12 +522,12 @@ class FollowingManager : public Manager{
}
auto now = mouse_emu::clock::now();
if (wparam > 1){
if (is_touch_down){
if (ctx.is_touch_down){
OutputDebugStringA("touch error\n");
is_touch_down = false;
ctx.is_touch_down = false;
ctx.last_ops_time = max(now, ctx.last_ops_time + ctx.delay_up);
mouse_emulator->emulate(
mouse_emu::event::up, last_touch_point.x, last_touch_point.y,
mouse_emu::event::up, ctx.last_touch_point.x, ctx.last_touch_point.y,
ctx.last_ops_time + mouse_emu::milliseconds(ctx.delay_up));
}
}else{
Expand All @@ -544,17 +546,17 @@ class FollowingManager : public Manager{
ctx.last_ops_time = max(now, ctx.last_ops_time);
}
mouse_emulator->emulate(mouse_emu::event::move, pt.x, pt.y, ctx.last_ops_time);
is_touch_down = true;
last_touch_point = pt;
ctx.is_touch_down = true;
ctx.last_touch_point = pt;
ctx.last_ops_time = max(now, ctx.last_ops_time + ctx.delay_down);
ctx.last_down_time = ctx.last_ops_time;
mouse_emulator->emulate(mouse_emu::event::down, pt.x, pt.y, ctx.last_ops_time);
}else if (input.dwFlags & TOUCHEVENTF_UP && is_touch_down){
is_touch_down = false;
}else if (input.dwFlags & TOUCHEVENTF_UP && ctx.is_touch_down){
ctx.is_touch_down = false;
ctx.last_ops_time = max(ctx.last_ops_time, max(now, ctx.last_down_time + ctx.delay_up));
mouse_emulator->emulate(mouse_emu::event::up, pt.x, pt.y, ctx.last_ops_time);
}else if ((input.dwFlags & TOUCHEVENTF_MOVE) && is_touch_down){
last_touch_point = pt;
}else if ((input.dwFlags & TOUCHEVENTF_MOVE) && ctx.is_touch_down){
ctx.last_touch_point = pt;
ctx.last_ops_time = max(now, max(ctx.last_ops_time, ctx.last_down_time + ctx.delay_drag));
mouse_emulator->emulate(mouse_emu::event::move, pt.x, pt.y, ctx.last_ops_time);
}
Expand All @@ -563,7 +565,11 @@ class FollowingManager : public Manager{
}

void setWindowForRecovery(HWND hwnd, mouse_emu::recovery_type type){
mouse_emulator->set_window_for_recovery(hwnd, type);
window_for_recovery = hwnd;
recovery_type = type;
if (mouse_emulator){
mouse_emulator->set_window_for_recovery(window_for_recovery, recovery_type);
}
}

protected:
Expand Down Expand Up @@ -694,5 +700,7 @@ DLLEXPORT bool hookdll_changeWindowAtrribute(HWND hWnd, HWND hWndInsertAfter, in
}

DLLEXPORT void hookdll_setWindowForRecovery(HWND hwnd, int type){

if (leadManager){
leadManager->setWinodForRecovery(hwnd, type);
}
}

0 comments on commit 347531d

Please sign in to comment.