win32 icon indicating copy to clipboard operation
win32 copied to clipboard

Desktop locked / WM_WTSSESSION_CHANGE message subscription

Open thefujii opened this issue 2 years ago • 5 comments

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?

thefujii avatar Jul 27 '22 13:07 thefujii

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 avatar Jul 31 '22 06:07 Far-Se

@Far-Se any idea why the isolate remains when hot reloading? Running into the same issue trying to record keyboard combinations on flutter windows

a-metta avatar Jul 31 '22 23:07 a-metta

@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 avatar Aug 01 '22 05:08 Far-Se

@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 avatar Aug 12 '22 12:08 thefujii

@thefujii Look at the example You need to add winHooks.addListener(this); on initstate and extend class with WinHookEventListener

Far-Se avatar Aug 12 '22 13:08 Far-Se