win32
win32 copied to clipboard
Desktop locked / WM_WTSSESSION_CHANGE message subscription
Hello, we are currently in need of getting WM_WTSSESSION_CHANGE message with parameters in flutter with FluentUI Basically we need to know when the desktop gets locked to switch user to appear offline in app.
Is there a way to use win32 plugin, or are there any plans of implementation of these messages?
Alternatively is there any way to detect this, either as one time action or with a continous checking, whether the desktop is locked or not with current tools?
Use SetWinEventHook
.
https://github.com/timsneath/win32/issues/509#issuecomment-1162208826
The issue is that it requires ReadMessage() to stay alive, which freezes main thread so you need to put it in a isolate. But when you hot restart your app that isolate stays there. So set it up, test it, then only run it when you are in kReleaseMode.
Alternatively, use this package I've made : https://pub.dev/packages/win32hooks
@Far-Se any idea why the isolate remains when hot reloading? Running into the same issue trying to record keyboard combinations on flutter windows
@Far-Se any idea why the isolate remains when hot reloading? Running into the same issue trying to record keyboard combinations on flutter windows
Because it's Windows related stuff and Dart can't control it. The only workaround I've found is to listen to some obscure shortcut and send PostQuitMessage(0);
when it's trigger. And I trigger it with normal SendInput from anywhere. Check the comment I've mentioned above.
What I haven't tried is to listen to custom messages, maybe you can try.
// WM_APPCOMMAND - 0x0319
// APPCOMMAND_HELP - 27
final msg = calloc<MSG>();
GetMessage(msg, hWnd, WM_APPCOMMAND, WM_APPCOMMAND);
return;
//... when you want to close the isolate
SendMessage(hWnd,WM_APPCOMMAND,APPCOMMAND_HELP);
Also there are packages that handle hotkeys, check out leanflutter package.
@Far-Se Alternatively, use this package I've made : https://pub.dev/packages/win32hooks
How does your package work? As far as I understand it, I should recieve events in runtime on
@override void onWinEventInfoReceived(WinEventStruct event) { print("WinEventInfo: ${event.toString()}"); }
But nothing is printing out. How can I actually apply it?
@thefujii Look at the example
You need to add winHooks.addListener(this);
on initstate and extend class with WinHookEventListener