Difference between revisions of "love.keyboard.getScancodeFromKey"

(Created page)
 
m
 
(4 intermediate revisions by the same user not shown)
Line 2: Line 2:
 
Gets the hardware scancode corresponding to the given key.
 
Gets the hardware scancode corresponding to the given key.
  
The location of a [[KeyConstant|key]] is based on the keyboard's current language layout, whereas [[Scancode|scancodes]] are the layout-independent representations of where the physical keys are.
+
Unlike [[KeyConstant|key constants]], Scancodes are keyboard layout-independent. For example the scancode "w" will be generated if the key in the same place as the "w" key on an American keyboard is pressed, no matter what the key is labelled or what the user's operating system settings are.
  
For example, pressing the key located where "q" is on a U.S. keyboard will produce the key "q" and the scancode "q" when using a U.S. keyboard layout, but when using a French keyboard layout it will produce the key "a" and the scancode "q".
+
Scancodes are useful for creating default controls that have the same physical locations on on all systems.
 
 
Scancodes are useful for creating default controls that have the same physical locations on on all keyboards.
 
 
== Function ==
 
== Function ==
 
=== Synopsis ===
 
=== Synopsis ===
Line 15: Line 13:
 
{{param|KeyConstant|key|The key to get the scancode from.}}
 
{{param|KeyConstant|key|The key to get the scancode from.}}
 
=== Returns ===
 
=== Returns ===
{{param|Scancode|scancode|The scancode corresponding to the given key.}}
+
{{param|Scancode|scancode|The scancode corresponding to the given key, or "unknown" if the given key has no known physical representation on the current system.}}
 
== See Also ==
 
== See Also ==
 
* [[parent::love.keyboard]]
 
* [[parent::love.keyboard]]
 
* [[love.keyboard.getKeyFromScancode]]
 
* [[love.keyboard.getKeyFromScancode]]
 +
* [[love.keyboard.isScancodeDown]]
 +
* [[love.keypressed]]
 +
* [[love.keyreleased]]
 
[[Category:Functions]]
 
[[Category:Functions]]
 
{{#set:Description=Gets the hardware scancode corresponding to the given key.}}
 
{{#set:Description=Gets the hardware scancode corresponding to the given key.}}
 
== Other Languages ==
 
== Other Languages ==
 
{{i18n|love.keyboard.getScancodeFromKey}}
 
{{i18n|love.keyboard.getScancodeFromKey}}

Latest revision as of 04:58, 18 December 2015

Available since LÖVE 0.9.2
This function is not supported in earlier versions.

Gets the hardware scancode corresponding to the given key.

Unlike key constants, Scancodes are keyboard layout-independent. For example the scancode "w" will be generated if the key in the same place as the "w" key on an American keyboard is pressed, no matter what the key is labelled or what the user's operating system settings are.

Scancodes are useful for creating default controls that have the same physical locations on on all systems.

Function

Synopsis

scancode = love.keyboard.getScancodeFromKey( key )

Arguments

KeyConstant key
The key to get the scancode from.

Returns

Scancode scancode
The scancode corresponding to the given key, or "unknown" if the given key has no known physical representation on the current system.

See Also

Other Languages