TolikPylypchuk / SharpHook

SharpHook provides a cross-platform global keyboard and mouse hook, event simulation, and text entry simulation for .NET
https://sharphook.tolik.io
MIT License
322 stars 32 forks source link

failed to disable right click menu with MouseHookEventArgs.SuppressEvent=true #99

Closed weil closed 3 months ago

weil commented 4 months ago

I created a simple sharphook c# program to disable the global right click menu: https://pastecode.io/s/mdu66mhk

I expected it could disable the global right click menu, not just the form right click. Is that a right expectation? Or it only disable the right click functionality within the form? Thanks for looking in it. Really appreciate it.

TolikPylypchuk commented 4 months ago

Hi! Thanks for posting this issue! I will look into it in the nearest future.

TolikPylypchuk commented 4 months ago

I've just tried reproducing it using the code you provided, and everything works correctly on my machine - when suppressing the mouse press/release events for Button2, no right-clicks go through.

Could you please describe in more detail, what happens on your machine? Do other applications register the right click and show a context menu?

weil commented 4 months ago

I've just tried reproducing it using the code you provided, and everything works correctly on my machine - when suppressing the mouse press/release events for Button2, no right-clicks go through.

Could you please describe in more detail, what happens on your machine? Do other applications register the right click and show a context menu?

even I set "e.SuppressEvent = true;", all other applications (e.g vs code, chrome) can still show the right click menu.

weil commented 4 months ago

I used other open source lib like " Gma.System.MouseKeyHook", i was able to stop the right click menu by doing "e.handled =true"

TolikPylypchuk commented 4 months ago

Could you please also tell me what Windows version you have and whether your project uses .NET Framework or the new .NET?

weil commented 4 months ago

Program Files\dotnet\shared\Microsoft.NETCore.App\8.0.4 windows: Windows 10 Pro

weil commented 4 months ago

I've just tried reproducing it using the code you provided, and everything works correctly on my machine - when suppressing the mouse press/release events for Button2, no right-clicks go through.

Could you please describe in more detail, what happens on your machine? Do other applications register the right click and show a context menu?

could you plz share me the zip of your program and .net version? I tried .net 7 on my side and still had the same issue. Thanks in advance.

TolikPylypchuk commented 4 months ago

I literally just used the code you provided without any changes. I used .NET 8, but I don't think there will be any difference between 7 and 8.

Can you add some code to see that the event handler is actually called? Like adding Debug.WriteLine or something like that. We should see whether just suppressing the event doesn't work, or the event handler doesn't work at all.

Also, you should either dispose the global hook when the window closes, or you should create it the following way:

new SimpleGlobalHook(runAsyncOnBackgroundThread: true);

This way the application will exit when you close the window. Otherwise it will keep running in the background since the global hook is still running on another thread.

TolikPylypchuk commented 4 months ago

Since I cannot reproduce the issue on my machine, there's not much I can actually do to help right now, unfortunately.

Could you maybe add some Debug.WriteLine statements to the event handler to see whether the hook works? Maybe, the handlers don't get called at all?

BinarySpike commented 4 months ago

all other applications (e.g vs code, chrome) can still show the right click menu.

FYI I've had issues with VS Code, Chrome, and VMWare Horizons. I can't quite recall the issue I had in chromium based apps, but in VMWare, it has some sort of keylogger protection. I'm pretty sure it uses DebugProc or something similar to catch and disable the hook.

TolikPylypchuk commented 3 months ago

@weil since I cannot reproduce this issue, I will close it due to inactivity, but we can continue the discussion and reopen it if necessary.