Git Product home page Git Product logo

Comments (2)

Patchnote-v2 avatar Patchnote-v2 commented on August 28, 2024 2

So long as you're not expecting simple-keyboard to handle detection of the mouse inputs like it can with a physical keyboard, this is easily achievable in just like how the numpad works in the full keyboard demo. In my project I'm using react-simple-keyboard.
This is how I define the mouse:

let commonKeyboardOptions = {
    ...
    syncInstanceInputs: true,
}

const keyboardMouseExtraOptions = {
    ...commonKeyboardOptions,
    layout: {
        default: ["{mouseextra2}", "{mouseextra1}"],
    },
    display: {
        "{mouseextra2}": "Mouse Extra 2 ↑",
        "{mouseextra1}": "↓ Mouse Extra 1",
    }
};

const keyboardMousePrimaryOptions = {
    ...commonKeyboardOptions,
    layout: {
        default: ["{wheelup}", "{mouse1} {mousemiddle} {mouse2}", "{wheeldown}"];,
    },
    display: {
        "{mouse1}": "Mouse 1",
        "{mouse2}": "Mouse 2",
        "{wheelup}": "Wheel Up",
        "{mousemiddle}": "Middle",
        "{wheeldown}": "Wheel Down",
    }
};

The HTML:

<div className="mouse">
    <Keyboard baseClass={"simple-keyboard-mouse-extra"}
              {...keyboardMouseExtraOptions}
    />
    <Keyboard baseClass={"simple-keyboard-mouse-primary"}
              {...keyboardMousePrimaryOptions}
    />
</div>

Some SCSS that's passable. It's not pretty but it is functional:

.mouse {
  display: flex;
  display-items: flex-end;
  text-align: center;

    .simple-keyboard-mouse-extra {
        display: flex;
        flex-direction: column;
        justify-content: center;
        width: 100px;
        
        .hg-button-mouseextra1, .hg-button-mouseextra2 {
            height: 85px;
        }
    }
      
    .simple-keyboard-mouse-primary {
        display: flex;
        flex-direction: column;
        justify-content: center;

        .hg-button-wheelup {
            flex: 0 0 100px;
        }
        .hg-button-wheeldown {
            flex: 0 0 100px;
        }
    }
}

Note that my project deals with external hotkey files for a different program, so the keycodes for mouse buttons are predetermined. When a mouse key is selected I look up the keycode and go from there.

let keycodes = {
    ...
    '{mouseextra2}': 251,
    '{mouseextra1}': 252,
    '{mousemiddle}': 253,
    '{wheeldown}': 254,
    '{wheelup}': 255,
}

How you handle storing of keybinds as well as detection of pressing hotkeys is up to you. For my use case it works great.

from simple-keyboard.

hodgef avatar hodgef commented on August 28, 2024

I would also vouch for a custom solution as shown by @Patchnote-v2. I will track this as a Proposal in case we want to make this a built-in in a future version.

from simple-keyboard.

Related Issues (20)

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.