Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Monitoring USB ports #251

Open
DarkPurpleKnight opened this issue Jun 12, 2021 · 10 comments
Open

Monitoring USB ports #251

DarkPurpleKnight opened this issue Jun 12, 2021 · 10 comments
Labels
enhancement New feature or request

Comments

@DarkPurpleKnight
Copy link

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?

@timsneath
Copy link
Contributor

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?

@timsneath timsneath added the enhancement New feature or request label Jun 19, 2021
@timsneath
Copy link
Contributor

Oh -- wondering if SetWindowsHookEx might allow installation of a hookproc to monitor these messages. Will investigate...

@DarkPurpleKnight
Copy link
Author

Flutter 2.10 includes stable Windows support.

@timsneath Does this have a positive effect on monitoring USB ports on Windows?

@timsneath
Copy link
Contributor

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.

@DarkPurpleKnight
Copy link
Author

@timsneath I didn't know the Dart runner yet. Thanks for your work and the tip.

@yanshouwang
Copy link

Oh -- wondering if SetWindowsHookEx might 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

@mortenboye
Copy link

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?

@yanshouwang
Copy link

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

@mortenboye
Copy link

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.

@SPiercer
Copy link

SPiercer commented Mar 3, 2024

What's the latest update on this ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

5 participants