Home>
In Unity, I want to get mouse input in the background (just click) when the window is inactive.
It works normally if it is active, but not if it is inactive.
The build did not change.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ClickMouse: MonoBehaviour
{
public void OnGUI ()
{
Event e = Event.current;
if (e.button == 0&&e.isMouse&&e.type == EventType.MouseDown)
{
this.gameObject.GetComponent<SpriteRenderer>(). color = new Color (1, 1, 1, 0);
}
}
}
There is an article about using Event to receive input, but I tried it, but it does not work.
https://qiita.com/kaikiofkaiki/items/f705716f9e45c11b5288
You can get keyboard input using "UnityRawInput" which is also introduced.
There is almost no other information and I'm stuck.
Supplemental information (FW/tool version etc.)Unity2018.4.12f1
-
Answer # 1
Related articles
- unity - bind left mouse button or tap in input system
- image switching by unity key input (c #)
- c # - [unity] format exception: input string was not in a correct format error
- c # - player production in unity (shooting game)
- c # - unity delegate basic cs0246 error
- c # - unity 2d breakout: i want to double the score for consecutive hits
- c # - error when creating unity class
- [unity] i want to move the instance with the mouse after creating the instance
- c # - [unity] object reference not set to an instance of an object error resolution
- c # - i want to stabilize the processing cycle of unity
- c # - [unity] i want to paste multiple textures on a game object
- c # - i want to get the text of unity toggle group
- c # - code error of script implemented by unity cannot be resolved
- about symbolic key input in unity
- c # - visual studio 2019 does not open when double-clicking a unity script
- c # - i want to temporarily disable key input
- c # - i can't attach a script in unity (beginner)
- c # - i want to make a combo attack with unity
- c # - input check is not performed
- c # - i want to read a txt file with unity and store it in an array
Related questions
- c # - player production in unity (shooting game)
- c # - please tell me how to use the additional components of unity's volunteer production
- c # - conversion from enum type to enum type
- c # - missingreferenceexception occurs even though there is a reference
- c # - i want to update the value
- c # - i want the camera to follow the player character in a tps game, but if i make multiple players in multiplayer, the camera
- c # - [unity] even though "has exit time" of animator is specified, it will transition to another state earlier than t
- c # - == becomes false even though the strings are equal
- c # - how to use start () in unity
- c # - in a script? error cs1056: unexpected character'?' is displayed even though there is no
It was solved by arriving at the word "Global hook".
By the way, it seems that global hooks in C # can only be low level hooks, but mouse and keyboard information can be obtained within that range.
If you have knowledge of other languages, it seems easy to implement in C ++.
Reference site
https://qiita.com/exliko/items/3135e4413a6da067b35d
Words that helped resolve
SetWindowsHookEx function, WH_MOUSE_LL