feat: detect key in background
This commit is contained in:
parent
3e34a7a048
commit
680481afad
13 changed files with 460 additions and 19 deletions
28
Assets/Scripts/ClickTest.cs
Normal file
28
Assets/Scripts/ClickTest.cs
Normal file
|
@ -0,0 +1,28 @@
|
|||
using SatorImaging.AppWindowUtility;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
|
||||
public class ClickTest : MonoBehaviour {
|
||||
[SerializeField] private TMP_Text text;
|
||||
private int _presses;
|
||||
private bool _pressed;
|
||||
private const int Key = 0xBF;
|
||||
|
||||
private void OnEnable() {
|
||||
AppWindowUtility.AlwaysOnTop = true;
|
||||
}
|
||||
|
||||
private void Update() {
|
||||
if (_pressed && Win32API.GetAsyncKeyState(Key) == 0) {
|
||||
Debug.Log("unpressed");
|
||||
_pressed = false;
|
||||
return;
|
||||
}
|
||||
if (!_pressed && Win32API.GetAsyncKeyState(Key) != 0) {
|
||||
Debug.Log("pressed");
|
||||
_presses++;
|
||||
text.text = _presses.ToString();
|
||||
_pressed = true;
|
||||
}
|
||||
}
|
||||
}
|
11
Assets/Scripts/ClickTest.cs.meta
Normal file
11
Assets/Scripts/ClickTest.cs.meta
Normal file
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 7a6ab8726a3100840b7f1ba17e278262
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
6
Assets/Scripts/Win32API.cs
Normal file
6
Assets/Scripts/Win32API.cs
Normal file
|
@ -0,0 +1,6 @@
|
|||
using System.Runtime.InteropServices;
|
||||
|
||||
public static class Win32API {
|
||||
[DllImport("User32.dll")]
|
||||
public static extern short GetAsyncKeyState(int vKey);
|
||||
}
|
3
Assets/Scripts/Win32API.cs.meta
Normal file
3
Assets/Scripts/Win32API.cs.meta
Normal file
|
@ -0,0 +1,3 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 8146fbf025e0444dae51ba3f7c693f8a
|
||||
timeCreated: 1712920866
|
Loading…
Add table
Add a link
Reference in a new issue