in terms of the character controller for an fps i want the caps lock to be an auto run function. shift is already a run button so i will just copy that but what do i put instead of...
//Run
if (Input.GetButton ("Shift")) {
moveDirection = new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical"));
moveDirection = transform.TransformDirection(moveDirection);
moveDirection *= RunSpeed;
}
Scribe and GlitchEnzo, yet my reputation isn't enough to vote you both down.
KeyCode.CapsLock and Event.capsLock only returns True if the key is pressed, not returning the state of the lock. There would be a way with importing System.Console namespace with the CapsLock function but Unity doesn't seem to import it... Must be some kind of a security issue. I also could take a use of it but couldn't find an answer yet.
System.Console.CapsLock only available when you are using the full mono, not .Net 2.0 Subset.
To change: Edit/Project Settings/Player,
Other Settings/Optimization/API Compatibility Level → .Net 2.0
After that System.Console.CapsLock will be available.
BUT!
Mono seems to be bugged, and this variable always return false.
Actually there are two ways to get Caps Lock info:
Copy UnityInstallDir\Editor\Data\Mono\lib\mono\2.0\System.Windows.Forms.dll to your Assets/Plugins folder. After that you can query Caps Lock state by the following code:
System.Windows.Forms.Control.IsKeyLocked(System.Windows.Forms.Keys.CapsLock)
or
System.Windows.Forms.Control.IsKeyLocked(System.Windows.Forms.Keys.Capital)
Using WinAPI:
Define an external function in a class:
[DllImport(“USER32.dll”)] public static extern short GetKeyState(int nVirtKey);