Overriding command/ctrl keys on web

Ever want to prevent your users from logging themselves out or refreshing their session by pressing CMD/CTRL-R ? The Xojo Web Framework has an exposed javascript command for doing that. In Session.Opening, try this:

Self.ExecuteJavaScript("XojoWeb.overrideMetaKey('r');")

Now if you run your project and press CTRL/CMD-R, the framework will capture the event and not let it go to the browser!

For those WebSDK devs out there, the parameters are:

  • key as string (key to intercept, notice I used lowercase r. if you use R, you’re capturing CMD-SHIFT-R)
  • targetElement as HTMLElement ( where the event listener is attached, defaults to document )
  • callback method (method that you want to be called when the command key is pressed. defaults to null. it looks like the callback method needs to take two parameters, the second appears to be the key name)
6 Likes

Nice trick!
One would do the same for the F5 key on Windows/Linux.

It’s possible from what I’ve read, but you can’t use the built-in capability because their code assumes the meta key is held down.