Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Auto Save

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <div class="container">
  <div class="shortcut-not-clicked-text">
    <p>No Keyboard Shortcut is Clicked</p>
    <p class="small-text">[click a + b to trigger the global shortcut]</p>
  </div>
  <div class="shortcut-clicked-text"><p> a + b shortcut is clicked</p>
  </div>
</div>
              
            
!

CSS

              
                /* Media Queries */

/* Small Devices*/

@media (min-width: 0px) {
  
* {
  box-sizing: border-box;
}

  
  body {
    margin: 0;
    padding: 0;
  }

  .container {
    background-color: lightpink;
    height: 100vh;
    width: 100%;
    /*targeting Chrome & Safari*/
    display: -webkit-flex;
    /*targeting IE10*/
    display: -ms-flex;
    display: flex;
    justify-content: center;
    /*vertical centering*/
    align-items: center;
    /*horizontal centering*/
    flex-direction: column;
    padding: 0 10px 0 10px;
  }

  .shortcut-not-clicked-text,
  .shortcut-clicked-text {
    font-size: 30px;
    width: 100%;
    text-align: center;
    font-family: monospace;
    /*targeting Chrome & Safari*/
    display: -webkit-flex;
    /*targeting IE10*/
    display: -ms-flex;
    display: flex;
    justify-content: center;
    /*vertical centering*/
    align-items: center;
    /*horizontal centering*/
    flex-direction: column;
    margin: 0;
    padding: 0;
  }

  .small-text {
    font-size: 20px;
  }

  .shortcut-clicked-text {
    display: none;
  }
}

/* Medium devices */

@media (min-width: 768px) {
  .shortcut-not-clicked-text,
  .shortcut-clicked-text {
    font-size: 70px;
  }

  .small-text {
    font-size: 30px;
  }
}

/* Large devices */

/* @media (min-width: 992px) {} */

/*Ipad pro view*/

/* 
@media (min-width: 1024px) {

} */

/* Extra Large devices */

/* @media (min-width: 1200px) {} */

              
            
!

JS

              
                /*Note that the use of the keyCode attribute on the key event should be 
avoided as MDN considers it a deprecated attribute. Therefore, the key 
attribute is used instead.*/

const shortcutNotClickedTextRef = document.getElementsByClassName(
  "shortcut-not-clicked-text"
)[0];
const shortcutClickedTextRef = document.getElementsByClassName(
  "shortcut-clicked-text"
)[0];

// Keep track of clicked keys
var isKeyPressed = {
  a: false, // ASCII code for 'a'
  b: false // ASCII code for 'b'
  // ... Other keys to check for custom key combinations
};

document.onkeydown = keyDownEvent => {
  //Prevent default key actions, if desired
  keyDownEvent.preventDefault();

  // Track down key click
  isKeyPressed[keyDownEvent.key] = true;

  // Check described custom shortcut
  if (isKeyPressed["a"] && isKeyPressed["b"]) {
    //for example we want to check if a and b are clicked at the same time
    //do something as custom shortcut (a & b) is clicked

    // show text indicating shortcut is clicked
    shortcutClickedTextRef.style.display = "flex";
    shortcutNotClickedTextRef.style.display = "none";
  }
};

document.onkeyup = keyUpEvent => {
  // Prevent default key actions, if desired
  keyUpEvent.preventDefault();

  // Track down key release
  isKeyPressed[keyUpEvent.key] = false;

  // when one of the keys is released, show text indicating
  // text is no longer clicked
  if (!isKeyPressed["a"] || !isKeyPressed["b"]) {
    shortcutClickedTextRef.style.display = "none";
    shortcutNotClickedTextRef.style.display = "flex";
  }
};

              
            
!
999px

Console