问题
I know that the whole concept of PWA is for a app to scale across all screen sizes I have written an IDE-like application (in a PWA), that is information dense, and I want my PWA to be portable across desktop OSs (mouse + keyboard), and tablets (touch + hardware keyboard).
My app is not really meant for mobile OSs. There are many keyboard short cuts, and whilst I could add UI elements to simulate these key presses, the screen is already action packed enough. The app simply doesn't belong on any platform without a hardware keyboard. But PWAs (with the hardware keyboard filter) are the perfect method of distribution for desktop OSs with modern browsers, so I'm in a bit of a pickle.
So, my question is - is there a way for a progressive web app (via the manifest or otherwise) to signal requires (or works best) with a hardware keyboard?
回答1:
Short answer - No Explicit way to find the availability of physical keyboard programmatically or to restrict your app to keyboard only devices by requesting browsers/search engines to make that restriction with any kind of meta data/scripts. Said that, you can't restrict the user by putting in the URL or your PWA web page in the address bar and requesting for it. All you can do is, on loading, you can do some checks like in the "alternate solution" and show a message to the user to use a computer with keyboard attached. If the soft keyboard is good enough to handle your checks, you are left with no luck!
There are some tricky solutions developers have experimented.
Alternate solution: Unfortunately, nothing you can rely on, without asking the user itself. On loading your app(or when ever you think it is appropriate to), prompt the user to press one of the shortcut, which you think its more appropriate for a user with physical keyboard. Wait for the even listener of that key combination. If the event is caught, then you can assume, user's keyboard is good with your shortcut solutions. Also give a button "Shortcut pressed" and another button "Not available in my keyboard" and on pressing, you can let the user know the app id not for them or even you can let them use it with mouse and menu option(which is more appropriate).
来源:https://stackoverflow.com/questions/50380960/is-there-a-way-to-flag-that-a-progressive-web-app-requires-a-hardware-keyboard