Keyboard Mapping Example

Directions:

  1. Open the console to see the logged messages.
  2. Press the specified keyboard combinations to trigger the corresponding actions:
  3. Change the Scope by Pressing any of the following Keys:
  4. Default Scope Mappings:
    1. Ctrl+A: Log "Ctrl+A pressed"
    2. Ctrl+S: Log "Ctrl+S pressed (does not activate save mode as the key overrides the default function)"
    3. Shift+Enter: Log "Shift+Enter pressed"
    4. Ctrl+Shift+D: Log "Ctrl+Shift+D pressed"
    5. Escape: Log "Escape pressed."
    6. Scope 1 Mappings
    7. Scope 2 Mappings
  5. Modify the keyboard mappings in the code and experiment with your own combinations and actions.

JavaScript Code:

const keyboardMapper = new KeyboardMapper();

      keyboardMapper.mapCombination("ctrl+a", () => {
        console.log("Ctrl+A pressed");
      });

      keyboardMapper.mapCombination("shift+enter", () => {
        console.log("Shift+Enter pressed");
      });

      keyboardMapper.mapCombination("ctrl+shift+d", () => {
        console.log("Ctrl+Shift+D pressed");
      });

      keyboardMapper.mapCombination("escape", () => {
        console.log("Escape pressed.");
      });

      keyboardMapper.mapCombination("0", () => {
        console.log("0 pressed. Changing scope to default.");
        // Change the scope (optional)
        keyboardMapper.setScope("default");
      });

      keyboardMapper.mapCombination("1", () => {
        console.log("1 pressed. Changing scope to scope1.");
        // Change the scope (optional)
        keyboardMapper.setScope("scope1");
      });

      keyboardMapper.mapCombination("ctrl+s", () => {
        console.log("Ctrl+S");
      });

      keyboardMapper.mapCombination("2,3,4,5", () => {
        console.log("2 pressed. Changing scope to scope2.");
        // Change the scope (optional)
        keyboardMapper.setScope("scope2");
      });

      keyboardMapper.mapCombination(
        "ctrl+c",
        () => {
          console.log("Ctrl+C");
        },
        "scope1"
      );

      keyboardMapper.mapCombination(
        "ctrl+z",
        () => {
          console.log("Ctrl+Z");
        },
        "scope2"
      );