Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

current Caps Lock state

Discussion in 'Scripting' started by VortexStudios, Feb 19, 2016.

  1. VortexStudios

    VortexStudios

    Joined:
    Jul 16, 2012
    Posts:
    84
    hello everyone!
    I'm looking for a way to get the current capslock state, but didn't have found anything that works :(
    any idea??
     
  2. steego

    steego

    Joined:
    Jul 15, 2010
    Posts:
    968
    I don't think thats possible in Unity I'm afraid, unless you write your own native plugin to get it.

    What you can do is handle key-down events with KeyCode.CapsLock, but this will not pick up the actual state of the capslock if it changes outside your game.

    Code (csharp):
    1.  
    2. class CapsLock : MonoBehaviour
    3. {
    4.     private bool m_CapsLock = false;
    5.     void Update()
    6.     {
    7.         if (Input.GetKeyDown(KeyCode.CapsLock)
    8.         {
    9.            m_CapsLock = !m_CapsLock;
    10.         }
    11.     }
    12. }
    13.  
     
  3. VortexStudios

    VortexStudios

    Joined:
    Jul 16, 2012
    Posts:
    84
    no, this is a "fake way" and didn't work if you are developing a password system for example, what I neet is a way to get the REAL caps lock status, propably I'll need to develop my native plugin for that :-/
     
  4. steego

    steego

    Joined:
    Jul 15, 2010
    Posts:
    968
  5. VortexStudios

    VortexStudios

    Joined:
    Jul 16, 2012
    Posts:
    84
    yes, I'm was reading this link right now xD I made my native plugin and it worked <3
    BUT! I've contacted the guys from Unity too asking if there something for this inside the engine, if have I'll post here, if not, I'll create a nice plugin with some stuff and publish on asset store :)
     
  6. retraffic

    retraffic

    Joined:
    Jul 2, 2014
    Posts:
    13
    any news on this?
     
  7. VortexStudios

    VortexStudios

    Joined:
    Jul 16, 2012
    Posts:
    84
    hey! yes! I had a hardware fail and lost it xD
    I'll try to recode it, and as it is a little more hard and may need some different code on each platform (and I didn't have time for it right now), I'll open the source on github...