generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Game Design
Home Search
 

Re: Using inputservice for keydown?

Previous Thread :: Next Thread 
KiwiTronik is not online. KiwiTronik
Joined: 18 Feb 2010
Total Posts: 3221
29 Dec 2014 09:34 PM
How can i do this?
I was told that you can use inputservice to check if TAB has been pressed, but the wiki link doesnt mention key down functions :/
Wiki link: http://wiki.roblox.com/index.php?title=API:Class/UserInputService
Report Abuse
025110 is not online. 025110
Joined: 23 Nov 2012
Total Posts: 57661
29 Dec 2014 09:37 PM
there's a key:byte number for it
Report Abuse
025110 is not online. 025110
Joined: 23 Nov 2012
Total Posts: 57661
29 Dec 2014 09:39 PM
http://wiki.roblox.com/index.php/Special_Characters

if (key:byte() == 48) then
Report Abuse
025110 is not online. 025110
Joined: 23 Nov 2012
Total Posts: 57661
29 Dec 2014 09:40 PM
[48 is the shift key]
Report Abuse
Unclear is not online. Unclear
Joined: 27 Aug 2011
Total Posts: 17060
29 Dec 2014 09:42 PM
"there's a key:byte number for it"

No point in doing that when your code reads a lot better using UserInputService instead. Lua is a high enough level language (far away from machine code) that the difference between these sorts of things is completely trivial, which is why readability is (almost) always preferred.

Use the InputBegan event from UserInputService. Recall that UserInputService is a service, so you should get the event like so...

game:GetService("UserInputService").InputBegan:connect(inputBegan)

We will create the inputBegan function. InputBegan (the event) returns an InputObject. If you look at the wiki, you will see that InputObjects have a property called KeyCode. This returns an Enum value (Enum.KeyCode) that you can use to compare values. If we wanted to print "hello" everytime we pressed the X key, we would get type the following...

function inputBegan(inputObject)
local keyCode = inputObject.KeyCode
if keyCode == Enum.KeyCode.X then
print("hello")
end
end

game:GetService("UserInputService").InputBegan:connect(inputBegan)

You can read more about the above in the following links...

http://wiki.roblox.com/index.php?title=InputBegan_(Event)
http://wiki.roblox.com/index.php?title=InputObject
http://wiki.roblox.com/index.php?title=API:Class/InputObject/KeyCode

Good luck!
Report Abuse
025110 is not online. 025110
Joined: 23 Nov 2012
Total Posts: 57661
29 Dec 2014 09:43 PM
whats the point of that if you can just do key:byte
Report Abuse
KiwiTronik is not online. KiwiTronik
Joined: 18 Feb 2010
Total Posts: 3221
29 Dec 2014 09:45 PM
Yes, but tab(9) doesnt work with mouse.Keydown
I heard using inputservice would work, somehow.
Report Abuse
Unclear is not online. Unclear
Joined: 27 Aug 2011
Total Posts: 17060
29 Dec 2014 09:46 PM
byte is nearly unreadable unless you know it by heart or refer to a chart. Commenting code for that is unnecessary as well. Why would you use byte? Making your code more unreadable is a ridiculous thing to do and is only done by people who really have no idea what they are doing, or are just trying to impress newbies with complex code.
Report Abuse
KiwiTronik is not online. KiwiTronik
Joined: 18 Feb 2010
Total Posts: 3221
29 Dec 2014 09:59 PM
Well what's the alternate for tab?
Report Abuse
Unclear is not online. Unclear
Joined: 27 Aug 2011
Total Posts: 17060
29 Dec 2014 10:05 PM
http://wiki.roblox.com/index.php?title=API:Enum/KeyCode

Enum.KeyCode.Tab will do.
Report Abuse
025110 is not online. 025110
Joined: 23 Nov 2012
Total Posts: 57661
29 Dec 2014 10:24 PM
lol you're telling me key:byte is complex and unreadable
Report Abuse
Unclear is not online. Unclear
Joined: 27 Aug 2011
Total Posts: 17060
29 Dec 2014 10:35 PM
It's a lot less readable than something that reads like pure English, haha. There is no way you really believe that comparing the numerical output of :byte() is more readable than comparing with Enum.KeyCode.
Report Abuse
CoffeeFlux is not online. CoffeeFlux
Joined: 02 Sep 2009
Total Posts: 1731
29 Dec 2014 10:39 PM
025110 you should stop before you sound sillier than you already do ;/


~CoffeeFlux. For you.
Report Abuse
verbalAKspray is not online. verbalAKspray
Joined: 09 Jul 2014
Total Posts: 23685
29 Dec 2014 10:44 PM
i understand what 025 is saying, doesn't look silly to me
Report Abuse
025110 is not online. 025110
Joined: 23 Nov 2012
Total Posts: 57661
29 Dec 2014 10:55 PM
jsing mine is easier

+who cares if your script doesnt read like english
Report Abuse
CoffeeFlux is not online. CoffeeFlux
Joined: 02 Sep 2009
Total Posts: 1731
29 Dec 2014 11:06 PM
"jsing mine is easier" not necessarily, you have to look up the bytecode each time

"+who cares if your script doesnt read like english"
oh my god are you serious
code readability matters
a lot
/lot/


~CoffeeFlux. For you.
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Game Design
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image