admin管理员组文章数量:1123342
I am trying to detect keypress from my MAUI C# desktop app which is minimized in background. Any help.
I have tried GlobalKeyboardHook I have tried using this `class GlobalKeyboardHook { private const int WH_KEYBOARD_LL = 13; private const int WM_KEYUP = 0x0101;
private delegate int LowLevelKeyboardProc(int nCode, IntPtr wParam, IntPtr lParam);
[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
private static extern IntPtr SetWindowsHookEx(int idHook, LowLevelKeyboardProc lpfn, IntPtr hMod, uint dwThreadId);
[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
private static extern bool UnhookWindowsHookEx(IntPtr hhk);
[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
private static extern IntPtr CallNextHookEx(IntPtr hhk, int nCode, IntPtr wParam, IntPtr lParam);
private IntPtr _hookID = IntPtr.Zero;
private LowLevelKeyboardProc _proc;
public GlobalKeyboardHook()
{
_proc = HookCallback;
}
public void Hook()
{
_hookID = SetWindowsHookEx(WH_KEYBOARD_LL, _proc, IntPtr.Zero, 0);
}
public void Unhook()
{
UnhookWindowsHookEx(_hookID);
}
private int HookCallback(int nCode, IntPtr wParam, IntPtr lParam)
{
if (nCode >= 0 && wParam == (IntPtr)WM_KEYUP)
{
int vkCode = Marshal.ReadInt32(lParam);
//MessageBox.Show($"Key released: {vkCode}");
if (vkCode == 9)
{
Global.Initiate_server?.SendMessage(Global.TrepCserver.Takescreenshot);
}
// Handle key release here
}
return (int)CallNextHookEx(_hookID, nCode, wParam, lParam);
}
}`
This works for wpf application but not maui targeting windows. Help. Is there 3rd party that could work or developing a class that could work for this function?
本文标签: Is there a way to hook keypress in background in C MAUI desktopStack Overflow
版权声明:本文标题:Is there a way to hook keypress in background in C# MAUI desktop? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736565412a1944695.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论