Last active
October 21, 2020 02:51
-
-
Save arsh5620/e36086559449d1b72e7807c1f86541d9 to your computer and use it in GitHub Desktop.
Unity CapsLock Quick Hack
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
public class UnityCapsLockScript : MonoBehaviour | |
{ | |
bool _isCapsLock = false; | |
void OnGUI() | |
{ | |
// https://answers.unity.com/questions/1464150/how-to-get-the-keyboardos-capslock-state.html | |
// Original thanks to cooldude5757 on unity answers | |
IsCapsLockOn(Event.current); | |
if (Event.current.isKey & Event.current.character > 0) | |
{ | |
Debug.Log($"Caps lock is {_isCapsLock}"); | |
} | |
} | |
// Must be called from OnGUI | |
public void IsCapsLockOn(Event e) | |
{ | |
if (e.isKey) | |
{ | |
if (e.character >= 'A' && e.character <= 'Z') | |
{ | |
if (e.shift) | |
{ | |
_isCapsLock = false; | |
} | |
else | |
{ | |
_isCapsLock = true; | |
} | |
} | |
else if (e.character >= 'a' && e.character <= 'z') | |
{ | |
if (e.shift) | |
{ | |
_isCapsLock = true; | |
} | |
else | |
{ | |
_isCapsLock = false; | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment