Files
sbox-public/engine/Sandbox.Engine/Systems/Input/Input.Keyboard.cs
s&box team 71f266059a Open source release
This commit imports the C# engine code and game files, excluding C++ source code.

[Source-Commit: ceb3d758046e50faa6258bc3b658a30c97743268]
2025-11-24 09:05:18 +00:00

52 lines
1.3 KiB
C#

using NativeEngine;
namespace Sandbox;
public static partial class Input
{
public static partial class Keyboard
{
/// <summary>
/// Keyboard key is held down
/// </summary>
public static bool Down( string keyName )
{
if ( Application.IsHeadless ) return false;
if ( Suppressed ) return false;
var code = NativeEngine.InputSystem.StringToButtonCode( keyName );
if ( code == ButtonCode.BUTTON_CODE_INVALID ) return false;
return CurrentContext.KeysCurrent.Contains( code );
}
/// <summary>
/// Keyboard key wasn't pressed but now it is
/// </summary>
public static bool Pressed( string keyName )
{
if ( Application.IsHeadless ) return false;
if ( Suppressed ) return false;
var code = NativeEngine.InputSystem.StringToButtonCode( keyName );
if ( code == ButtonCode.BUTTON_CODE_INVALID ) return false;
return !CurrentContext.KeysPrevious.Contains( code ) && Down( keyName );
}
/// <summary>
/// Keyboard key was pressed but now it isn't
/// </summary>
public static bool Released( string keyName )
{
if ( Application.IsHeadless ) return false;
if ( Suppressed ) return false;
var code = NativeEngine.InputSystem.StringToButtonCode( keyName );
if ( code == ButtonCode.BUTTON_CODE_INVALID ) return false;
return CurrentContext.KeysPrevious.Contains( code ) && !Down( keyName );
}
}
}