GetKeyState: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
(Added description, return info, proper tested example) |
||
Line 1: | Line 1: | ||
__NOTOC__ | |||
{{Client function}} | |||
This function determines if a certain key is pressed or not. | |||
==Syntax== | ==Syntax== | ||
<syntaxhighlight lang="lua">bool getKeyState ( | <syntaxhighlight lang="lua"> | ||
bool getKeyState ( string keyName ) | |||
</syntaxhighlight> | |||
===Required Arguments=== | |||
*'''keyName:''' The name of the key you're checking state of. See [[Key names]]. | |||
===Returns=== | |||
Returns ''true'' if the specified key is pressed, ''false'' if it isn't or if an invalid key name is passed. | |||
==Example== | |||
This clientside example prints a message when "p" is pressed, and a different one for the "control+p" combination. | |||
<syntaxhighlight lang="lua"> | |||
-- define a function that outputs a message if control is pressed, and a different one if it isn't | |||
function printMessageFunction() | |||
-- if the left or right control keys are pressed, the user has pressed the "control+p" combo | |||
if getKeyState( "lctrl" ) == true or getKeyState( "rctrl" ) == true then | |||
outputChatBox ( "You have pressed 'control+p'." ) | |||
-- if none of those were pressed, he just pressed the "p" key | |||
else | |||
outputChatBox ( "You have pressed 'p'." ) | |||
end | |||
end | |||
-- bind the "p" key to our function | |||
bindKey( "p", "down", "Print message", printMessageFunction ) | |||
</syntaxhighlight> | |||
==See Also== | |||
{{Client_world_functions}} |
Revision as of 22:07, 4 August 2007
This function determines if a certain key is pressed or not.
Syntax
bool getKeyState ( string keyName )
Required Arguments
- keyName: The name of the key you're checking state of. See Key names.
Returns
Returns true if the specified key is pressed, false if it isn't or if an invalid key name is passed.
Example
This clientside example prints a message when "p" is pressed, and a different one for the "control+p" combination.
-- define a function that outputs a message if control is pressed, and a different one if it isn't function printMessageFunction() -- if the left or right control keys are pressed, the user has pressed the "control+p" combo if getKeyState( "lctrl" ) == true or getKeyState( "rctrl" ) == true then outputChatBox ( "You have pressed 'control+p'." ) -- if none of those were pressed, he just pressed the "p" key else outputChatBox ( "You have pressed 'p'." ) end end -- bind the "p" key to our function bindKey( "p", "down", "Print message", printMessageFunction )
See Also
- createSWATRope
- getBirdsEnabled
- getCoronaReflectionsEnabled
- getGarageBoundingBox
- getGaragePosition
- getGarageSize
- getGroundPosition
- getInteriorFurnitureEnabled
- getNearClipDistance
- getPedsLODDistance
- getRoofPosition
- getScreenFromWorldPosition
- getVehiclesLODDistance
- getWorldFromScreenPosition
- isAmbientSoundEnabled
- isLineOfSightClear
- isWorldSoundEnabled
- processLineOfSight
- resetAmbientSounds
- resetBlurLevel
- resetColorFilter
- resetCoronaReflectionsEnabled
- resetNearClipDistance
- resetPedsLODDistance
- resetVehiclesLODDistance
- resetWorldSounds
- setAmbientSoundEnabled
- setBirdsEnabled
- setColorFilter
- setCoronaReflectionsEnabled
- setInteriorFurnitureEnabled
- setInteriorSoundsEnabled
- setNearClipDistance
- setPedsLODDistance
- setVehiclesLODDistance
- setWorldSoundEnabled
- testLineAgainstWater
- areTrafficLightsLocked
- getAircraftMaxHeight
- getAircraftMaxVelocity
- getCloudsEnabled
- getFarClipDistance
- getFogDistance
- getGameSpeed
- getGravity
- getHeatHaze
- getInteriorSoundsEnabled
- getJetpackMaxHeight
- getMinuteDuration
- getMoonSize
- getOcclusionsEnabled
- getRainLevel
- getSunColor
- getSunSize
- getTime
- getTrafficLightState
- getWeather
- getWindVelocity
- getSkyGradient
- getPlayerBlurLevel
- getZoneName
- isGarageOpen
- removeWorldModel
- resetFarClipDistance
- resetFogDistance
- resetHeatHaze
- resetMoonSize
- resetRainLevel
- resetSkyGradient
- resetSunColor
- resetSunSize
- resetWindVelocity
- restoreAllWorldModels
- restoreWorldModel
- setAircraftMaxHeight
- setAircraftMaxVelocity
- setCloudsEnabled
- setFarClipDistance
- setFogDistance
- setGameSpeed
- setGarageOpen
- setGravity
- setHeatHaze
- setInteriorSoundsEnabled
- setMinuteDuration
- setMoonSize
- setOcclusionsEnabled
- setRainLevel
- setSkyGradient
- setSunColor
- setSunSize
- setTime
- setTrafficLightState
- setTrafficLightsLocked
- setWeather
- setWeatherBlended
- setWindVelocity
- setJetpackMaxHeight
- setPlayerBlurLevel