-->

Is it possible to block the Windows Key from a web

2019-02-27 19:00发布

问题:

I have a fairly sophisticated Single Page Application, with a nice little menu system (similar to Windows 8 start menu). I'd like for my users to hit the Windows key to open this menu when within my application. I have this successfully functioning, however it also brings up the Microsoft Windows start menu.

Is there a way (from a web browser) I can "block" the Microsoft Windows Start Menu from appearing when I hit the Windows Key within my web app?

I'm using latest jQuery, knockoutJS, and any necessary JavaScript plugin to accomplish this task.

回答1:

Write a custom binding handler for your button action -

ko.bindingHandlers.windowsKey = {
    init: function (element, valueAccessor, allBindingsAccessor, viewModel) {
        var value = ko.utils.unwrapObservable(valueAccessor());

        $(element).keydown(function (e) {
            if (e.which === 91 || e.which == 93) {
                value(viewModel);
            }
        });
    }
};

As per the question of whether you can disable a button in Windows from the browser, see the answer that Daniel White posted that no, this cannot be done.