How to lock keyboard in jquery?

Asked

Viewed 1,097 times

2

How to lock the entire keyboard in jquery, especially the Esc key for full screen, I want you not to leave the fullscreen when pressing Esc.

example:

$(document).keydown(function(e) { 
    if (e.keyCode == 13) { return false; }
    if (e.keyCode == 27) { return false; }    
});

It is a user registration and it is on a specific computer only for the registration of these users, the pc will have no other function than this.

  • Which browser exits full screen with ESC? I tried Chrome and Firefox and both ignore by default.

  • All leave the fullscreen with ESC as far as I know, at least the internet explorer comes out...

  • Have you tried it $(document).keydown(function(e) { return false; }); ?

  • He keeps coming out of the fullscreen Sergio!

  • Probably this is independent of the Browser, but a function of the OS. However, I find it advisable to prevent the user from leaving full-screen...

  • It is a registration program and the user cannot leave the full screen, I disabled F1 with Cód: Document.onhelp = Function() { Return(false); } window.onhelp = Function() { Return(false); } probably has some way to disable Esc

  • Besides giving return false;, have tried e.preventDefault();?

  • Yes, and it didn’t work...

Show 3 more comments

1 answer

5

For security reasons, no browser will allow any page to take away from the user the most basic controls - such as minimizing the window, switching to another one, etc. Nothing prevents, for example, the use of Alt+Tab or Ctrl+Alt+Del - and from there the user will probably be able to do what he wants. I do not know in depth the mode fullscreen, but I know that the user needs to give permission to enter full screen, and I’m sure that the browser does not allow you to overload the command to exit it, whatever it is.

I suggest you "take a step back" and assess exactly what problem are you trying to solve (and not only the imagined solution).

It is a registration program and the user cannot leave the full screen...

Register in what? Can’t leave the full screen why? Is it to resolve any technical issues on your website/service/app (and if so, which one?) or for security reasons? Are there alternatives? It is important that these details are well thought out - and the most appropriate solution employed (whether using native browser features, or using OS-specific plugins and/or features). For in the general case the only correct answer to your question is: "it is impossible to block the keyboard completely in jQuery".

  • It is a user register and it stays in a specific computer only for the registration of these users, the pc will not have another function, I’m thinking of using software languages like Delphi to devise this system, I need suggestions...

  • @user3230262 In this case, I would suggest investigating browsers specific to a single site (site-specific browser). It’s a feature that some browsers offer (including IE9+ and Google Chrome) to create a desktop shortcut that opens a "streamlined" browser window - no menus, address bar and so on - restricted to accessing a single website or domain. I can not indicate a specific solution, because I did not use any in practice, but the linked site (Wikipedia, in English) shows some options at the bottom of the page

  • 1

    @user3230262 Also, find out how to use "Kiosk mode" (Kiosk mode) of your operating system - in order to actually prevent the user from exiting/switching applications using the usual controls. So you will have an application that only accesses a single page, and that cannot be exchanged by non-privileged users.

  • mgibsonbr, I will search on Kiosk mode and site-specific-browser, thank you!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.