Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Runtime.InteropServices;
- using UnityEngine;
- public class KeyExtension
- {
- #if PLATFORM_STANDALONE_WIN
- [DllImport("user32.dll")]
- public static extern short GetKeyState(int key);
- const int VK_CAPITAL = 0x14;
- const int VK_NUMLOCK = 0x90;
- const int VK_SCROLL = 0x91;
- public static bool IsCapsLockOn()
- {
- return (GetKeyState(VK_CAPITAL) & 0xffff) != 0;
- }
- public static bool IsNumLockOn()
- {
- return (GetKeyState(VK_NUMLOCK) & 0xffff) != 0;
- }
- public static bool IsScrollLockOn()
- {
- return (GetKeyState(VK_SCROLL) & 0xffff) != 0;
- }
- #else
- public static bool IsCapsLockOn()
- {
- return KeyValue(KeyCode.CapsLock);
- }
- public static bool IsNumLockOn()
- {
- return KeyValue(KeyCode.Numlock);
- }
- public static bool IsScrollLockOn()
- {
- return KeyValue(KeyCode.ScrollLock);
- }
- #endif
- public static bool KeyValue(KeyCode keyCode)
- {
- if (Application.isPlaying)
- {
- return (Input.GetKey(keyCode));
- }
- else
- {
- return (Event.current.keyCode == keyCode);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment