Coder Social home page Coder Social logo

karl-horning / key-codes-keyboard-event-handler Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 0.0 3.94 MB

A simple JavaScript function to handle key events and display the pressed key and its key code dynamically in the HTML.

Home Page: https://codepen.io/karlhorning/pen/MBjMrX

License: MIT License

HTML 12.81% CSS 65.43% JavaScript 21.76%
codepen dom-manipulation javascript keyboard-events user-interface animation css html responsive frontend

key-codes-keyboard-event-handler's Introduction

Key Codes Keyboard Event Handler

A simple JavaScript function to handle key events and display the pressed key and its key code dynamically in the HTML.

Project Demo

Table of Contents

About

This project provides a straightforward JavaScript function (checkKeycode) that listens for keyboard events and updates the content of an HTML element with the class "keycode" to display the pressed key and its corresponding key code. The code is written using modern JavaScript syntax and is well-documented for ease of use.

Features

  • Dynamic display of pressed key and key code.
  • Support for modern browsers using the 'key' property and a fallback for older browsers using 'keyCode'.
  • Additional handling for the space key to display "Space" instead of an empty string.

Demo

View the demo on CodePen.

Usage

  1. Include the JavaScript file in your HTML:

    <script src="path/to/script.js"></script>
  2. Ensure that you have an HTML element with the class "keycode" in your document:

    <div class="keycode"></div>
  3. Add an event listener to call the checkKeycode function on keyboard events:

    document.addEventListener("keydown", checkKeycode);

Installation

  1. Clone the repository:

    git clone https://github.com/Karl-Horning/key-codes-keyboard-event-handler.git
  2. Copy the script.js file into your project.

  3. Include the script in your HTML file as mentioned in the usage section.

Contributing

Contributions are welcome! Please follow these guidelines:

  1. Fork the repository.
  2. Create a new branch for your feature or bug fix.
  3. Make your changes and ensure that the project still works.
  4. Create a pull request with a clear description of your changes.

License

This project is licensed under the MIT License.

Contact

For any inquiries or support related to this project, please contact Karl Horning using any of the links in the 'Author' section.

Author

Karl Horning: GitHub | LinkedIn | CodePen

key-codes-keyboard-event-handler's People

Contributors

karl-horning avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.