Skip to content

Instantly share code, notes, and snippets.

@hecomi
Created December 16, 2021 14:39
Show Gist options
  • Save hecomi/c9037049db7b54b7134efc7fcc8a522f to your computer and use it in GitHub Desktop.
Save hecomi/c9037049db7b54b7134efc7fcc8a522f to your computer and use it in GitHub Desktop.
...
var window = uwcWinObj.window;
var localPos = uwcWinObj.transform.InverseTransformPoint(targetHit_.point);
var windowLocalX = (int)((localPos.x + 0.5f) * window.width);
var windowLocalY = (int)((0.5f - localPos.y) * window.height);
var desktopX = window.x + windowLocalX;
var desktopY = window.y + windowLocalY;
var coord = new Vector2(desktopX, desktopY);
NwndWin32API.SetForegroundWindow(window.handle);
NwndWin32API.SetFocus(window.handle);
if (isStickClicked_) {
touchDispatcher.Touch(coord);
} else if (isStickTouched_) {
touchDispatcher.Hover(coord);
}
...
using System;
using System.Runtime.InteropServices;
namespace NWindow
{
public static class NwndWin32API
{
public const uint WM_LBUTTONDOWN = 0x201;
public const uint WM_LBUTTONUP = 0x202;
public const uint MK_LBUTTON = 0x0001;
[DllImport("user32.dll")]
public static extern int SetFocus(IntPtr hWnd);
[DllImport("user32.dll")]
public static extern int SetForegroundWindow(IntPtr hWnd);
[DllImport("user32.dll")]
public static extern int SendMessage(IntPtr hWnd, uint msg, IntPtr wParam, IntPtr lParam);
[DllImport("user32.dll")]
public static extern int PostMessage(IntPtr hWnd, uint msg, IntPtr wParam, IntPtr lParam);
[DllImport("user32.dll", SetLastError = true)]
static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
public static IntPtr MakeLParam(int x, int y)
{
return (IntPtr)((y << 16) | (x & 0xffff));
}
public static void SendMouseClick(IntPtr hWnd, int x, int y)
{
var lParam = MakeLParam(x, y);
SetForegroundWindow(hWnd);
SetFocus(hWnd);
SendMessage(hWnd, WM_LBUTTONDOWN, new IntPtr(MK_LBUTTON), lParam);
SendMessage(hWnd, WM_LBUTTONUP, new IntPtr(MK_LBUTTON), lParam);
}
}
}
@berezecki
Copy link

Hello, great job. I would like to know how do uWindowCapture + VR. Can you help me please ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment