Coder Social home page Coder Social logo

motion-key's Introduction

motion-key

A keyboard configuration for your motion.

Requirements

  • macOS
    • Currently, sendKeyStroke.ts is dependend on macOS
    • Welcome to Pull Request for supporting another platform
  • web camera

Feature

  • Bind keystroke to your motion
  • Support gesture like ๐Ÿ‘ โœŒ๏ธ
  • Configuration by JavaScript ~/.config/motion-key/motion-key.config.js

Installation

https://github.com/azu/motion-key/releases/latest

  1. Download a binary from the latest releases
  2. Install app

โš ๏ธ This app is not signed. So, OS show warning about it.

Additional installation steps on macOS:

  1. Select motion-key.app
  2. Open context menu and Click "Open"

โš ๏ธ require permission on macOS. Open the app, and you need to add permission for motion-key.app

  • Accessibility
    • use accessibility permission to get activeWindow object
    • activeWindow includes active app info like bundle.id, url, title.
  • Screen Recording
    • use Screen Recording permission to use web camera

Config

You can write config file in ~/.config/motion-key/motion-key.config.js.

Config location:

  • ~/.config/motion-key/motion-key.config.js

You can control reaction for pixel diffs:

module.exports = ({ type, activeWindow, payload }) => {
    if (type === "PixelChangeAction") {
        // ignore diffs less than 5% of capture
        if (payload.diffPercent < 5) {
            return;
        }
        return {
            key: "ArrowDown"
        };
    } else if (type === "GestureAction") {
        return {
            key: "ArrowUp"
        };
    }
}

You can change the config for each application:

const muPdf = ({ type }) => {
    if (type === "PixelChangeAction") {
        return {
            key: "j"
        }
    } else if (type === "GestureAction") {
        return {
            key: "k"
        }
    }
};

module.exports = ({ type, activeWindow, payload }) => {
    const bundleId = activeWindow?.owner?.bundleId;
    if (bundleId === 'info.efcl.mu-pdf-viewer') {
        return muPdf({ type });
    }
    if (type === "PixelChangeAction") {
        return {
            key: "ArrowDown"
        }
    } else if (type === "GestureAction") {
        return {
            key: "ArrowUp"
        }
    }
}

You can set key for each Gesture:

module.exports = ({ type, activeWindow, payload }) => {
    if (type === "PixelChangeAction") {
        return {
            key: "ArrowDown"
        }
    } else if (type === "GestureAction") {
        if (payload.type === "๐Ÿ‘") {
            return { key: "ArrowUp" }
        }
        if (payload.type === "โœŒ๏ธ") {
            return { key: "ArrowRight" }
        }
    }
}

You can set nextActionIntervalMs to throttle keys.

motion-key ignore actions until the passage of nextActionIntervalMs.

module.exports = ({ type, activeWindow, payload }) => {
    if (type === "PixelChangeAction") {
        return {
            key: "ArrowDown",
            nextActionIntervalMs: 5 * 1000
        }
    } else if (type === "GestureAction") {
        return {
            key: "ArrowUp",
            nextActionIntervalMs: 5 * 1000
        }
    }
}

For more details, see Config.ts.

Recipe

Only work on Kindle.app

const kindle = ({ type, payload }) => {
    if (type === "PixelChangeAction") {
        // large motion to next page
        if (payload.diffPercent < 10) {
            return;
        }
        return {
            key: "Space"
        }
    } else if (type === "GestureAction") {
        // ๐Ÿ‘ next page
        if (payload.type === "๐Ÿ‘") {
            return { key: "Space" }
        }
        // โœŒ๏ธ prev page
        if (payload.type === "โœŒ๏ธ") {
            return { key: "Space", modifier: { "shift": true } }
        }
    }
};

module.exports = ({ type, activeWindow, payload }) => {
    const bundleId = activeWindow?.owner?.bundleId;
    if (bundleId === "com.amazon.Kindle") {
        return kindle({ type, payload })
    }
}

Releases

npm version {patch,minor,major}
git push --tags

Contributing

  1. Fork it!
  2. Create your feature branch: git checkout -b my-new-feature
  3. Commit your changes: git commit -am 'Add some feature'
  4. Push to the branch: git push origin my-new-feature
  5. Submit a pull request :D

License

MIT

motion-key's People

Contributors

azu avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  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.