mirror of
https://github.com/Facepunch/sbox-public.git
synced 2026-01-05 04:48:19 -05:00
This commit imports the C# engine code and game files, excluding C++ source code. [Source-Commit: ceb3d758046e50faa6258bc3b658a30c97743268]
52 lines
1.3 KiB
C#
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 );
|
|
}
|
|
}
|
|
}
|