using System; using System.Runtime.InteropServices; using System.Security; namespace SFML { namespace Window { //////////////////////////////////////////////////////////// /// /// Input handles real-time input from keyboard and mouse. /// Use it instead of events to handle continuous moves and more /// game-friendly inputs /// //////////////////////////////////////////////////////////// public class Input : ObjectBase { //////////////////////////////////////////////////////////// /// /// Get the state of a key /// /// Key to check /// True if key is down, false if key is up //////////////////////////////////////////////////////////// public bool IsKeyDown(KeyCode key) { return sfInput_IsKeyDown(This, key); } //////////////////////////////////////////////////////////// /// /// Get the state of a mouse button /// /// Button to check /// True if button is down, false if button is up //////////////////////////////////////////////////////////// public bool IsMouseButtonDown(MouseButton button) { return sfInput_IsMouseButtonDown(This, button); } //////////////////////////////////////////////////////////// /// /// Get the state of a joystick button /// /// Identifier of the joystick to check (0 or 1) /// Button to check /// True if button is down, false if button is up //////////////////////////////////////////////////////////// public bool IsJoystickButtonDown(uint joystickId, uint button) { return sfInput_IsJoystickButtonDown(This, joystickId, button); } //////////////////////////////////////////////////////////// /// /// Get the mouse X position /// /// Current mouse left position, relative to owner window //////////////////////////////////////////////////////////// public int GetMouseX() { return sfInput_GetMouseX(This); } //////////////////////////////////////////////////////////// /// /// Get the mouse Y position /// /// Current mouse top position, relative to owner window //////////////////////////////////////////////////////////// public int GetMouseY() { return sfInput_GetMouseY(This); } //////////////////////////////////////////////////////////// /// /// Get a joystick axis position /// /// Identifier of the joystick to check (0 or 1) /// Axis to get /// Current axis position, in the range [-100, 100] (except for POV, which is [0, 360]) //////////////////////////////////////////////////////////// public float GetJoystickAxis(uint joystickId, JoyAxis axis) { return sfInput_GetJoystickAxis(This, joystickId, axis); } //////////////////////////////////////////////////////////// /// /// For internal use only, construct the instance from a direct pointer to the internal object /// /// Internal pointer to the input object //////////////////////////////////////////////////////////// public Input(IntPtr thisPtr) : base(thisPtr) { } //////////////////////////////////////////////////////////// /// /// Handle the destruction of the object /// /// Is the GC disposing the object, or is it an explicit call ? //////////////////////////////////////////////////////////// protected override void Destroy(bool disposing) { // Nothing to do here, Input instances are owned by the C library } #region Imports [DllImport("csfml-window"), SuppressUnmanagedCodeSecurity] static extern bool sfInput_IsKeyDown(IntPtr This, KeyCode Key); [DllImport("csfml-window"), SuppressUnmanagedCodeSecurity] static extern bool sfInput_IsMouseButtonDown(IntPtr This, MouseButton Button); [DllImport("csfml-window"), SuppressUnmanagedCodeSecurity] static extern bool sfInput_IsJoystickButtonDown(IntPtr This, uint JoyId, uint Button); [DllImport("csfml-window"), SuppressUnmanagedCodeSecurity] static extern int sfInput_GetMouseX(IntPtr This); [DllImport("csfml-window"), SuppressUnmanagedCodeSecurity] static extern int sfInput_GetMouseY(IntPtr This); [DllImport("csfml-window"), SuppressUnmanagedCodeSecurity] static extern float sfInput_GetJoystickAxis(IntPtr This, uint JoyId, JoyAxis Axis); #endregion } } }