• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
seegatesite header

Seegatesite.com

Seegatesite.com - Programming Tutorial , Sharing , How and Learn Together

  • TOOLS
    • Bootstrap Navbar Online Generator
    • Customize Sidebar Menu Bootstrap 3
    • Bootstrap Demo
  • ADVERTISE
  • CATEGORIES
    • Android
    • Blogging Tips
    • Database
    • CSS
    • Info Gadget
    • Javascript
    • Linux
    • PHP
    • Various
    • WordPress
  • Q&A
  • PHP
  • JAVASCRIPT
  • JQUERY
  • ANGULAR
  • WORDPRESS
  • SEO
  • REACT
🏠 » Javascript » Handling Javascript Keyboard Events With JQuery Hotkeys Plugin

Handling Javascript Keyboard Events With JQuery Hotkeys Plugin

By Sigit Prasetya Nugroho ∙ March 30, 2017 ∙ Javascript ∙ Leave a Comment

Share : TwitterFacebookTelegramWhatsapp

The use of keyboard shortcuts in web applications are often needed by the user. Javascript can handle keyboard event functions, so developers can use it well. On jQuery, a plugin named hotkeys.js can easily add a handler for the keyboard events with a lot of combinations.

Supported by technology and hardware that is getting better, the use of jquery will not burden the system browser in client side again. The use of jQuery hotkeys plugin will save your time in create the keyboard events in javascript.

If without the plugin, the use of keyboard codes javascript like the following example:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
var isCtrl = false;
document.onkeyup=function(e){
    if(e.which == 17)
    {
        isCtrl=false;
    }
}
 
document.onkeydown=function(e){
    if(e.which == 17) isCtrl=true;
    if(e.which == 83 && isCtrl == true)
    {
         alert('test 1 2 3 4 5 6 .....');
         return false;
    }
}

Please try by pressing “ctrl+s” on a web page browser, what happens?
Without jQuery plugin, you can run the javascript hotkeys. But you have to know the keyboard codes reference, below the following list of keycode in javascript

Keyboard Shortcut And Keycode Javascript Reference

Of course using Hotkeys jquery plugins will be faster in writing code.

Table of Contents

  • 1 JQuery Hotkeys Plugin
    • 1.1 Thus my article about Handling Javascript Keyboard Events With JQuery Hotkeys Plugin, hope useful.

JQuery Hotkeys Plugin

According to the official website of jQuery Hotkeys is a plug-in that lets you easily add and remove handlers for keyboard events anywhere in your code supporting almost any key combination.

The use of this plugin is quite simple:

1
2
3
$('input.foo').bind('keydown', 'F9', function(){
  alert("this is F9");
});

But I am a little having problems when using ctrl + s on hotkeys plugin. When the input field get focus, keyboard event ctrl + s can not be run properly. Maybe I’m not good to applying them. So using javascript to handle this problem in the following ways

1
2
3
4
5
6
7
8
$(document).keydown(function(event) {
        if((event.ctrlKey || event.metaKey) && event.which == 83) {
           alert("hello this is ctrl+s trigger");
            event.preventDefault();
            return false;
        };
    }
);

Maybe anyone can help me?

If you would like to see an example of the use of hotkeys plugin in full please visit JQuery hotkeys example.

There are some important things to note about how to implement a keyboard event handler in the web application.

  1. Avoid defining keyboard shortcut that has been provided by the browser, for example Ctrl + P to print.
  2. Use keywords that are rarely used as F1 – F9.
  3. Use the keyboard event handler wisely ,please do not confuse the user

Thus my article about Handling Javascript Keyboard Events With JQuery Hotkeys Plugin, hope useful.

Another Javascript Related Post :

  • Adept Using Datatables Plugin In 10 Minutes For Beginners (Tutorial)
  • The Using Of Reactstrap And React-Table, Suitable For Beginners
  • Tutorial Create Simple Block UI Using React JS
  • How To Implement Login Page And Protected Route ReactJS
  • Complete Tutorial React Router Dom For Beginners (Easy-To-Understand)
  • The Right Way Understanding React Lifecycle For Beginners

Avatar for Sigit Prasetya Nugroho

About Sigit Prasetya Nugroho

This site is a personal Blog of Sigit Prasetya Nugroho, a Desktop developer and freelance web developer working in PHP, MySQL, WordPress.

Reader Interactions

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Time limit is exhausted. Please reload CAPTCHA.

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Primary Sidebar

Welcome to my Home,

Avatar for Sigit Prasetya NugrohoThis site is a personal Blog of Sigit Prasetya Nugroho, a Desktop developer and freelance web developer working in PHP, MySQL, WordPress.



Popular Articles

Checked checkbox AdminLTE Bootstrap in Jquery

November 4, 2014 By Sigit Prasetya Nugroho 7 Comments

Simple create date format validation with jqueryUI

December 21, 2014 By Sigit Prasetya Nugroho Leave a Comment

Create Simple Progress Bar for Fake Online Generator with Jquery

January 10, 2015 By Sigit Prasetya Nugroho Leave a Comment

22+ Coolest Free Jquery Plugin For Premium Theme

October 3, 2015 By Sigit Prasetya Nugroho Leave a Comment

Easy Build Your Anti Copy Paste Plugin

October 6, 2015 By Sigit Prasetya Nugroho Leave a Comment

Popular Tags

adminlte (15) adsense (13) adsense tips (4) affiliate amazon (13) amazon (12) Android (8) angular (16) angular 4 (12) angular 5 (4) asin grabber (3) Bootstrap (27) codeigniter (5) create wordpress theme (5) crud (8) css (6) free wordpress theme (7) google adsense (4) imacros (4) increase traffic (6) jquery (34) laravel (10) laravel 5 (5) learn android (5) modal dialog (5) mysql (6) nodeJs (4) optimize seo (4) pdo (6) php (30) plugin (53) pos (7) Publisher Tips (5) react (3) Reactjs (7) SEO (37) theme (17) tutorial angular (5) tutorial angular 4 (6) tutorial javascript (10) tutorial javascript beginners (4) twitter (3) widget (3) wordpress (18) wordpress plugin (13) XMLRPC (5)




  • About
  • Contact Us
  • Disclaimer
  • Privacy Policy
  • Terms and Conditions

©2021 Seegatesite.com