win32
win32 copied to clipboard
Monitoring USB ports
Hi Tim,
For a Flutter app for the Windows Desktop, I'm looking for a way to monitor changes to the USB ports. FYI, the Flutter app should respond to plugging in or unplugging a USB joystick/gamepad.
Does the win32 package provide a suitable feature that I have overlooked?
Looks like RegisterDeviceNotification is the way to go about it: https://docs.microsoft.com/en-us/windows/win32/devio/registering-for-device-notification
However, this requires intercepting the message loop for a WM_DEVICECHANGE message. I think the only way you can do that is from the runner itself; I don't think there's any extensibility mechanism built into Flutter to allow this to be intercepted from Dart, even with the APIs wrapped with win32.
@cbracken, any thoughts on this?
Oh -- wondering if SetWindowsHookEx might allow installation of a hookproc to monitor these messages. Will investigate...
Flutter 2.10 includes stable Windows support.
@timsneath Does this have a positive effect on monitoring USB ports on Windows?
Not particularly: the same notes above apply, since this is really about integrating with the operating system through calling Win32 APIs rather than anything in the UI itself.
One minor update is that we now have an experimental runner written in Dart: https://pub.dev/packages/win32_runner
This is not supported or maintained by the team as a whole, and it has some sizeable caveats (e.g. it supports packages but not plugins) but it provides another path to writing the message handler above.
@timsneath I didn't know the Dart runner yet. Thanks for your work and the tip.
Oh -- wondering if
SetWindowsHookExmight allow installation of a hookproc to monitor these messages. Will investigate...
@timsneath Can we use this function to hook message in flutter? I have tried this with WH_KEYBOARD_LL but it doesn't work
Would https://api.flutter.dev/flutter/dart-ffi/NativeCallable/NativeCallable.listener.html help with any of this?
@yanshouwang here you mention something about creating a message-only window in dart. Can you share more details about that?
Would https://api.flutter.dev/flutter/dart-ffi/NativeCallable/NativeCallable.listener.html help with any of this?
@yanshouwang here you mention something about creating a message-only window in dart. Can you share more details about that?
Here is the code I use to listen drives state, win32_util
Would https://api.flutter.dev/flutter/dart-ffi/NativeCallable/NativeCallable.listener.html help with any of this? @yanshouwang here you mention something about creating a message-only window in dart. Can you share more details about that?
Here is the code I use to listen drives state, win32_util
Thank you very much! I'll take a look.
What's the latest update on this ?