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 adamchakov · Aug 06, 2014 at 01:28 PM · keypresssimulate

simulate a keypress from a script

hey guys , is it possible to simulate a key press with a script like , when the game starts i want the spacebar to be pressed withtout me pressing it , i want it to be pressed from the script ! ,thanks.

Comment
Add comment
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

2 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by petrnita · May 04, 2015 at 09:35 AM

This is solution: http://answers.unity3d.com/answers/958624/view.html

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 Kiwasi · May 04, 2015 at 10:04 AM 0
Share

This one is also relevant

http://answers.unity3d.com/questions/28473/simulating-key-presses.html

avatar image
0

Answer by tanoshimi · Aug 06, 2014 at 01:31 PM

No that I'm aware of. I can't think why you'd need to do this though. Let's say your current code has something like:

 void Update() {
   if(Input.GetKey(KeyCode.Space)){
     DoSomethingWhenSpaceIsPressed();
   }
 }

Then to "simulate" that keypress when the game starts, you'd simply have to add:

 void Start() {
   DoSomethingWhenSpaceIsPressed();
 }

Or have I misinterpreted your question?

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 adamchakov · Aug 06, 2014 at 02:48 PM 0
Share

hey @tanoshimi thanks for the help but i think u misunderstood me a little :D ...what i wanted is , when the game starts or like when i enter a trigger , i want the Spacebar to be activated (pressed) from the script in realtime , without me pressing it on the keyboard

avatar image screenname_taken · Aug 06, 2014 at 02:53 PM 0
Share

Yeah, but the important thing is Why?

If it's just that you want the game to do a function that is tied to your space bar, then to perform it again simply call the function by itself. And if the code is not in a function on its own and you don't want to make it so, just copy paste the code.

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Press Ui Button To Simulate Keypress 3 Answers

How could i execute a command move for a fighting game? 3 Answers

Best way to handle keypress? 3 Answers

Odd input glitch 2 Answers

Need to press key twice to react 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