Git Product home page Git Product logo

keylock's Introduction

Keylock

Keylock is another coffee-time project I undertook during a tranquil coffee break at my favoured spot. It aims to fulfil a simple yet significant need—locking the keyboard on a macOS system (tested on MacBook Pro M1 Pro devices) to ease the cleaning process. Sometimes, a cleaning spree demands a pause on the keystrokes to avoid any unintended inputs, and that's where keylock comes into play. Crafted with Swift and harnessing the capabilities of macOS's native libraries, this small utility seamlessly locks the keyboard until you decide it's time to bring it back to action.

Build and Execute

Building and executing keylock is straightforward. Given the Swift nature of the project, you can utilise Swift's build system to manage the process. Here's how you would do it:

$ swift build
$ swift run

A POSIX Makefile with an install target is also provided for convenience. Without a target it would simply just run swift build -c release.

Usage

On invocation, the keyboard will remain locked until the specified unlock sequence is triggered. Not every key is locked, though; Brightness, Play/Pause, Rewind, Fast Forward, Volume, and Caps Lock keys are not locked. Mouse movement is also intact.

USAGE: keylock [--debug] [--timer <timer>]

OPTIONS:
  -d, --debug             Enable debug mode.
  -t, --timer <timer>     Exit after a specified number of seconds.
  -h, --help              Show help information.

N.B. The unlock sequence is ^U.

Design Notes

Keylock utilises the Core Graphics framework to tap into the keyboard events. By creating an event tap, it intercepts keyDown and keyUp events, effectively locking the keyboard. The heart of this functionality lies in the EventHandler.swift file, where the setupEventTap and handleKeyEvent methods orchestrate the locking and unlocking mechanism. The unlock sequence is triggered by a specific key combination, hardcoded at the minute, Control + U, allowing a smooth transition back to a functioning keyboard once your cleaning is done.

Contributing

Discover an issue or see a pathway to enhancement? Or perhaps you have a query? Feel free to open an issue or a pull request. Your engagement is always valued and appreciated!

License

Distributed under the MIT License. See LICENSE for more information.

keylock's People

Contributors

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