Advertisement
iRadEntertainment

Untitled

Jun 23rd, 2024
520
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.46 KB | None | 0 0
  1. using Godot;
  2. using System;
  3. using System.Runtime.InteropServices;
  4.  
  5. public partial class RSMousePass : Node
  6. {
  7.     // GetActiveWindow() retrieves the handle of the currently active window on the desktop.
  8.     [DllImport("user32.dll")]
  9.     public static extern IntPtr GetActiveWindow();
  10.  
  11.     //  SetWindowLong() modifies a specific flag value associated with a window.
  12.     [DllImport("user32.dll")]
  13.     private static extern int SetWindowLong(IntPtr hWnd, int nIndex, uint dwNewLong);
  14.    
  15.     private const int GwlExStyle = -20;
  16.    
  17.     // "Properties" of the window to be set, Layered is to have transparent pixels, Transparent is to make the window click-through
  18.     private const uint WsExLayered = 0x00080000;
  19.     private const uint WsExTransparent = 0x00000020;
  20.  
  21.     // index reference of the window
  22.     private IntPtr _hWnd;
  23.  
  24.     public override void _Ready()
  25.     {
  26.         // Get the reference of the game window
  27.         _hWnd = GetActiveWindow();
  28.  
  29.         // setting the flags of becoming a layered and transparent window
  30.         // SetWindowLong(_hWnd, GwlExStyle, WsExLayered | WsExTransparent);
  31.         SetWindowLong(_hWnd, GwlExStyle, WsExLayered);
  32.     }
  33.  
  34.     // Call this method via your preferred detection algorythm (personally I check the
  35.     // pixel under cursor to have alpha < 0.5f but you do you)
  36.     public void SetClickThrough(bool clickthrough)
  37.     {
  38.         if (clickthrough)
  39.         {
  40.             SetWindowLong(_hWnd, GwlExStyle, WsExLayered | WsExTransparent);
  41.         }
  42.         else
  43.         {
  44.             SetWindowLong(_hWnd, GwlExStyle, WsExLayered);
  45.         }
  46.     }
  47. }
  48.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement