zazoum
1
I tried three ways:
1.)
function OnGUI() {
var e : Event = Event.current;
Debug.Log(e.capsLock) ;
}
2.)
function Update(){
if (Input.GetKey(KeyCode.CapsLock)) {
Debug.Log("true");
}
else
{
Debug.Log("false");
}
}
3.)
import System;
function Update () {
print(Console.CapsLock);
}
The first two give me true on when CappsLock is CONSTANTLY PRESSED regardless of it is on or off.
The third gives false always.
All three give false even if CapsLock is on. Why?
I have win7 x64 .NET 2.0.
You can solve this as following:
using System.Runtime.InteropServices;
[DllImport("user32.dll")]
public static extern short GetKeyState(int keyCode);
bool isCapsLockOn = false;
void Start()
{
isCapsLockOn = (((ushort)GetKeyState(0x14)) & 0xffff) != 0;//init stat
}
void Update()
{
if(Input.GetKeyDown(KeyCode.CapsLock))
{
isCapsLockOn = !isCapsLockOn ;
//......
}
}
system
2
Have you tried using a boolean value that’s beeing toggled each time caps lock is pressed? (sry for code in c# I’m clueless when it comes to java:P )
private bool _capsToggled = false;
public void Update() {
if( Input.GetKey(KeyCode.CapsLock) ) {
_capsToggled = !_capsToggled; //Toggle the boolean
Debug.Log( "Caps Lock toggled: " + _capsToggled.ToString() );
}
}
//Then of course when you want to perform whatever it is you want to do when caps lock is toggled you could use
if( _capsToggled )
//Do this if caps is toggled
else
//Do this if not