How to passthrough Mouse to Desktop?

Godot Version

4.2.2

Question

I have the basic get_viewport().transparent_bg = true

Though I am hung up trying to just pass all clicks. This way a user can still use their desktop and the pet at the same time. It’s a slime ball pet that walks along your taskbar , eats foods and does other things.

no firsthand experience with this but this topic might help

https://forum.godotengine.org/t/mousepassthrough-for-non-same-applications/49284/6

I had seen that but I don’t use c sharp. I only have gdscript. I do appreciate the suggestion though.

Well after even more looking around it seems the desktop passthrough was a “bug” in version 3. So I doubt they will bring it back again anytime soon.

what platforms are you developing for? windows only?

Hey. Yea, I am only on Windows. I don’t see me going off into mac or linux in any near future as I am having a time just learning as is.

I been doing smaller projects… like tiny. music player, old school aol chat bot, and now the slime ball pet thing. I started with too big a scope when i first was doing ideas.

the c# by @KitzuGG 's i tested it and it works. You can add it to your project, as far as i can tell that is your best option.

So if interested, here is how to get started.

--

Untitled

in the create script, for language select “c#.” Name the file “MyWindowClickThrough.cs”

Why? For Godot to “see” the c# class, the name of the class and the file name must match. So if the class name is MyWindowClickThrough then the file name must be MyWindowClickThrough.cs

--

Now attach the script to a Node2D.

--

From Project > Tools > C# > choose Create C# solution.

If your c# source code stops working, repeat the step above.

--

copypaste the code below into MyWindowClickThrough.cs

public partial class MyWindowClickThrough:Godot.Node2D {
	[System.Runtime.InteropServices.DllImport("user32.dll")]
	public static extern System.IntPtr GetActiveWindow();
	[System.Runtime.InteropServices.DllImport("user32.dll")]
	private static extern int SetWindowLong(System.IntPtr hWnd, int nIndex, uint dwNewLong);
	private const int k_gwlExStyle = -20;
	private const uint k_wsExLayered = 0x00080000;
	private const uint k_wsExTransparent = 0x00000020;
	private System.IntPtr m_handle;
	public override void _Ready() {
		m_handle = GetActiveWindow();
		SetWindowLong(m_handle, k_gwlExStyle, k_wsExLayered | k_wsExTransparent);
		Godot.GD.Print("Hello, world!");
	}
	public void SetClickThrough(bool a_click_through) {
		if(a_click_through) {
			SetWindowLong(m_handle, k_gwlExStyle, k_wsExLayered | k_wsExTransparent);
		}
		else {
			SetWindowLong(m_handle, k_gwlExStyle, k_wsExLayered);
		}
	}
}

When you run your project, in the console you should see “Hello, world!” and your ENTIRE project window should be click-through.

If you get it working and you are interested, I can follow up and add basic configuration options. Such as the ability to toggle click through.

PLEASE BACKUP YOUR CURRENT PROJECT
PLEASE BACKUP YOUR CURRENT PROJECT
PLEASE BACKUP YOUR CURRENT PROJECT

Hey again. Thank you, I do appreciate all the effort but as I said earlier I don’t use c sharp as I already struggle with gdscript. I believe it’s called Mono build for Godot. Though I did make sure by checking my build of 4.2.2 standard and it does not include create c solution or the create a c sharp script.

Should we have a Admin lock this topic?