| |
|
|
| 06 Apr 2014 09:25 PM |
| game.Players.LocalPlayer:GetMouse().KeyDown:connect(function(key) print(key) end) |
|
|
| Report Abuse |
|
|
|
| 06 Apr 2014 09:27 PM |
| Which key is that line referring too? |
|
|
| Report Abuse |
|
|
NeonRiver
|
  |
| Joined: 12 Feb 2013 |
| Total Posts: 4936 |
|
| |
|
|
| 06 Apr 2014 09:31 PM |
All of them. KeyDown is called anytime any key is pressed, and it passes in the key that was pressed.
So that line will print every key hit from then on. If you want something to happen only when a certain key is pressed you can check against it as follows:
game.Players.LocalPlayer:GetMouse().KeyDown:connect(function(key) if key == 'r' then print("The 'r' key was hit!") end end)
Also note that this only works in localscripts, because server scripts don't have access to the mouse (which also is the keyboard). |
|
|
| Report Abuse |
|
|
NeonRiver
|
  |
| Joined: 12 Feb 2013 |
| Total Posts: 4936 |
|
| |
|
|
| 06 Apr 2014 09:34 PM |
What would the enter key be called? The right enter. |
|
|
| Report Abuse |
|
|
|
| 06 Apr 2014 09:35 PM |
Wrong. It should be the convention of the person who answered the question. I much rather have all my code follow the same format and call print as a function such as print(args) rather than print args.
Please don't try to correct what is already correct. |
|
|
| Report Abuse |
|
|
|
| 06 Apr 2014 09:41 PM |
If you want to start working with non-character keys you will need to use the character literal function ":byte()"
For a reference list please check the wiki: http://wiki.roblox.com/index.php/Taking_keyboard_input
So we can just adapt the old code I posted as follows: game.Players.LocalPlayer:GetMouse().KeyDown:connect(function(key) if key:byte() == 13 then print("The '↵ Enter' key was hit!") end end)
There are a few other ways as well, such as by comparing the key to a representation of a character from an int, or by using the escape sequences that represent these characters. |
|
|
| Report Abuse |
|
|
NeonRiver
|
  |
| Joined: 12 Feb 2013 |
| Total Posts: 4936 |
|
| |
|
|
| 06 Apr 2014 09:50 PM |
NeonRiver, Both work.
print "Test" print("Test")
both of these output the same exact thing. Both work. Neither are wrong in technical standards. The only time they are wrong is when you switch between using them. It's called convention. Things that don't HAVE to be one way, but ARE. I call print(args) because all other functions I use (be that I wrote them or they are base functions included) are called as function(args). |
|
|
| Report Abuse |
|
|
baheeg
|
  |
| Joined: 19 Jul 2010 |
| Total Posts: 72846 |
|
|
| 06 Apr 2014 10:21 PM |
Neon
no it should be what he said because the function requires an end + parenthesis and the if statement requires an end |
|
|
| Report Abuse |
|
|
Goulstem
|
  |
| Joined: 04 Jul 2012 |
| Total Posts: 7177 |
|
|
| 06 Apr 2014 10:47 PM |
local mouse = game.Players.Goulstem:GetMouse()
mouse.KeyDown:connect(function(key) print("Pressed Key: "..key) end)
>Pressed Key: (Key that I pressed) |
|
|
| Report Abuse |
|
|