Giter VIP home page Giter VIP logo

unityrawinput's Introduction

Description

Wrapper over Windows Raw Input API to hook for the native input events. Allows receiving input events even when the Unity application is in background (not in focus).

Will only work on Windows platform.

Only keyboard and mouse input is detected.

Installation

Download and import the package: UnityRawInput.unitypackage.

Usage

Enable Run In Background in project's player settings; if not enabled, expect severe mouse slowdown when the application is not in focus elringus#19 (comment).

Initialize the service to start processing input messages:

RawInput.Start();

Optionally, configure whether input messages should be handled when the application is not in focus and whether handled messages should be intercepted (both disabled by default):

RawInput.WorkInBackground = true;
RawInput.InterceptMessages = false;

Add listeners to handle input events:

RawInput.OnKeyUp += HandleKeyUp;
RawInput.OnKeyDown += HandleKeyDown;

private void HandleKeyUp (RawKey key) { ... }
private void HandleKeyDown (RawKey key) { ... }

Check whether specific key is currently pressed:

if (RawInput.IsKeyDown(key)) { ... }

Stop the service:

RawInput.Stop();

Don't forget to remove listeners when you no longer need them:

private void OnDisable ()
{
    RawInput.OnKeyUp -= HandleKeyUp;
    RawInput.OnKeyDown -= HandleKeyDown;
}

Find usage example in the project: https://github.com/Elringus/UnityRawInput/blob/master/Assets/Runtime/LogRawInput.cs.

List of the raw keys with descriptions: https://docs.microsoft.com/en-us/windows/win32/inputdev/virtual-key-codes.

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.