KeyDown (Event): Difference between revisions

From Legacy Roblox Wiki
Jump to navigationJump to search
>GoldenUrg
initial from experience
m Text replacement - "<SyntaxHighlight code="lua">" to "<syntaxhighlight lang="lua">"
 
(22 intermediate revisions by 8 users not shown)
Line 1: Line 1:
{{CatUp|Events}}
<onlyinclude>{{Event|name = KeyDown
|arguments = [[String]] ''key''
|description = Fired when a Key is pressed (the ''key'' is the key).
|object = Mouse
|}}</onlyinclude>


{|
{{clear floats}}
|<onlyinclude>{{Event|name=KeyDown
|arguments=[[String]] ''key''
|description= Fired when a Key is pressed (the ''key'' is the key)
|object= [[RBX.lua.Mouse (Object)|Mouse]]
|}}</onlyinclude>
|}


== Description ==
== Description ==
The ''key'' argument is the pressed key. Letter keys are lowercase.
The ''key'' argument is the pressed key. Letter keys are lowercase.
 
{{Example|<syntaxhighlight lang="lua">
== Example ==
local function onKeyDown( key )
<pre>
   print("Key:", key, " Code:", string.byte(key))
function onKeyDown( key )
   print( "Key:", key, " Code:", string.byte(key) )
end
end
mouse.KeyDown:connect( onKeyDown )
mouse.KeyDown:connect(onKeyDown)
</pre>
</syntaxhighlight>}}


== Limitations ==
== Limitations ==
* Not all keys generate this event (For example, "/" key if chat is enabled).
* Not all keys generate this event (For example, "/" key if chat is enabled).
* Some keys generate the same string as other keys.
* Some keys generate the same string as other keys.
* It's possible for the string to be empty (possibly due to "\0" key code).  
* It's possible for the string to be empty (possibly due to "\0" key code).


[[Category:Events]]
[[Category:Events]]

Latest revision as of 06:18, 27 April 2023

KeyDown ( String key )
Description Fired when a Key is pressed (the key is the key).
Member of: Mouse


Description

The key argument is the pressed key. Letter keys are lowercase.

Example
local function onKeyDown( key )
  print("Key:", key, " Code:", string.byte(key))
end
mouse.KeyDown:connect(onKeyDown)


Limitations

  • Not all keys generate this event (For example, "/" key if chat is enabled).
  • Some keys generate the same string as other keys.
  • It's possible for the string to be empty (possibly due to "\0" key code).