Giter Club home page Giter Club logo

unity-raw-input'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 #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/unity-raw-input/blob/main/Assets/Runtime/LogRawInput.cs.

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

unity-raw-input's People

Contributors

elringus avatar repiteo avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

unity-raw-input's Issues

One more raw mouse button request

Hi @elringus, love RawInput, it's saved my project. Just donated $10. I know you've said the project is keyboard only, but can I make a direct $150 donation for you to add mouse button functionality? I need the raw mouse buttons, but this is well beyond my coding abilities. Please let me know if you're interested, and thank you for the great asset!

Terminology is not consistent with Unity

GetKeyDown should indicate a singular frame press and then false until repressed.
while GetKey should indicate just a true or false of if the key is being held down.

See Input in Unity.

Unity3d new Input System

I'm using your package to take keyboard input even when the unity application does not have focus. Unfortunately, I noticed that this is not woking when the active input handling is set to "Both" (old input system package + new input system package). I need the new input system to take the input from my joystick. Do you know why this is not working and how to fix it? Thanks in advance.

RawInput fires with every input not only the one specified + not working in build

Hello! this is Drift_EX from twitter.

I'm trying to use this solution to have Unity fire events when not in focus, but:

In the Editor the RawInput function (button down/up functions) get called even if the button pressed is a total different one.

And, when I compile the project the RawInput doesn't work at all.

Note: I am using this with Unity 2019.1.5f1

Closing

Hi!
I'm trying to use UnityRawInput on Unity 2019.2
When I pushing the keyboard Unity Editor or builded project just imidiately closing without any error or bug report ask

Hide the app from taskbar

Hello Great Job!

I want to ask you how can i completely hide the app from taskbar but still run in background?

Device?

Will this asset also allow me to see the raw input device where the input is coming from?

Get the real value behind OEM[1..10]

Hi, thanks for making this package available !

I'm using UnityRawInput to make a screencast plugin.

Do you know if there is a way to get the real key behind OEM1, OEM2, ... and such ? Same for N0, N1, etc.

On an azerty keyboard, OEM1 is & but it will be something else on another layout.

How can I read the Mouse

How can I use the package to read Mouseinput? It works perfectly with Keys but it doesn't change to true if I want to use it with my mouse.

`Debug.Log(RawKeyInput.IsKeyDown(RawKey.LeftButton));`

That doesn't work...

rawInputBinding

Hi.
I love this solution ! thank you.
one question more than an issue.
is there a way to assign a RawKey from a string. the reverse of "key.ToString()"
I'd like to rebind the key mapping, so i need a way to re-assign the list of "RawKey key" on my app start-up.

Issues with 2020 version of unity

Just found this and started using it to detect inputs outside of unity. It works perfectly well however once I press play and test it still works fine however after pressing play again to stop the test it then seems to lag my typing on every other application apart from unity

In the example, RawKeyInput.InterceptMessages not assigned in a build

With the given example RawInputTest.cs, RawKeyInput.InterceptMessages is assigned in OnValidate(), which works in editor, but in a build OnValidate() doesn't get called. The OnValidate() docs specify "Called in the editor only". Not really a bug but can confuse a person if you're building off the example and don't know the limitation of OnValidate(). Great project otherwise!

Any leads on how to add Joystick Inputs?

Priviat,
Do you have any leads on how to add Joystick Inputs?
I would like to receive input events from the xboxOne Controller while the app is not focused.
Best,

Severe mouse slowdown/latency when my Unity app runs, but only on one computer, not another

I'm getting extremely slow, laggy, barely controllable mouse movement when my Unity build is running. When I run the same app on my older computers however, it runs perfectly.

The mouse movement is better when over the Unity app window, but still slow.

I've narrowed it down to the RawInput code, but again, only one machine runs it slow; the other two (substantially weaker) machines run it with RawInput perfectly.

I've tried to illustrate the difference in mouse control by drawing little circles, first inside the Unity app window, the outside. The RawInput script is inactive in the first gif, active in the second. You can see in the second how the mouse goes flying off at the end, this is a result of the latency. How can I narrow down the cause?

rawNoLag

rawLag

Get input from mouse

This is a really cool library!
wanted to ask if there is a way to get input from mouse (movement and button press)

Translating from Unity's input system to RawInput

I'm converting my code from Unity's input system to RawInput, but I'm having trouble with the two functions OnKeyUp and OnKeyDown. My game uses dozens of keys, how can I convert it from the Unity input system to RawInput? The sample script only has one example each for LogKeyUp and LogKeyDown. I started giving each button its own function, like in the picture below, and it's not working; all keys trigger all functions.

image

For example, my previous code looked like this:

if (Input.GetKeyDown(KeyCode.B)) {...}
if (Input.GetKeyUp(KeyCode.B)) {...}		

if (Input.GetKeyDown(KeyCode.S)) {...}
if (Input.GetKeyUp(KeyCode.S)) {...}	

etc.

How should that look in RawInput?

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.