Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
1
Question by Mike Ledwards · Dec 06, 2010 at 07:31 PM · fpscontrollerrun

How do you say if("Capslock") is on?

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;
    }

Comment
Add comment · Show 2
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Jesus_Freak · Dec 06, 2010 at 07:34 PM 0
Share

it says that in the script reference, click on the first enumerations word, then keyCode, and there's a whole list of possible keyboard inputs.

avatar image Jesus_Freak · Dec 06, 2010 at 07:51 PM 0
Share

yes. the enumerations in the runtime class.

4 Replies

· Add your reply
  • Sort: 
avatar image
2
Best Answer

Answer by Scribe · Dec 06, 2010 at 08:40 PM

If you want to ask if they press the capslock key then you do something you use:

if (Input.GetKey(KeyCode.CapsLock))

but if you want to check whether capslock is switched on or not you should use:

Event.capsLock (this returns true when capslock is switched on)

Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Proclyon · Dec 07, 2010 at 12:07 AM 0
Share

Is this a direct state check or a key event check? I'm used to checking key events for states and checking states after an UpdateState routine.

avatar image Scribe · Dec 07, 2010 at 03:41 PM 0
Share

file:///Applications/Unity/Unity.app/Contents/Documentation/Documentation/ScriptReference/Event-capsLock.html this is the page about the event, I think it is a key event check but i'm not certain sorry

avatar image
1
Best Answer

Answer by GlitchEnzo2 · Dec 06, 2010 at 07:38 PM

You want to use KeyCode.CapsLock

if (Input.GetKey(KeyCode.CapsLock)) {
    // put code here
}
Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
5

Answer by BitMiller · Jan 17, 2011 at 10:41 AM

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.

http://msdn.microsoft.com/en-us/library/system.console.capslock.aspx

import System;

function Start () { print(Console.CapsLock) }

says: Unknown identifier: 'CapsLock'.

Of course I've also tried import System.Console; print(CapsLock);

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image TheRaven · Aug 27, 2013 at 05:52 AM 0
Share

I'm with you Bit$$anonymous$$iller cant actually query if the Capslock is engaged.

avatar image
1

Answer by darvinda · Oct 06, 2015 at 11:35 AM

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:

  1. 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)

  2. Using WinAPI: Define an external function in a class:

    [DllImport("USER32.dll")] public static extern short GetKeyState(int nVirtKey);

and query it:

 (GetKeyState(0x14) & 1)>0) // 0x14 = VK_CAPITAL (Caps Lock)

return value:

If the high-order bit is 1, the key is down; otherwise, it is up.

If the low-order bit is 1, the key is toggled.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

2 People are following this question.

avatar image avatar image

Related Questions

Exporting Projects Missing Elements 1 Answer

i need to make a player deal damage to another player during multiplayer 1 Answer

Where is the FPSPlayer Script? 0 Answers

Player moving without input 2 Answers

[FPS] Is it good to have the same character for AI and Players ? 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges