🚢
Airship
  • Getting Started
    • Welcome to Airship
    • Installing Airship
  • TypeScript
    • Overview
    • AirshipBehaviour
      • Adding Inspector Properties
      • AirshipSingleton
      • Using Component Decorators
      • Accessing Other Components
  • Publishing
    • Publish Game
    • Developer Console
  • Networking
    • Multiplayer
    • Local Server Mode
    • Network Signals
    • Network Functions
    • Network Identity
    • Network Transform
  • Input
    • User Input
      • Actions
      • Keyboard
      • Mouse
    • Proximity Prompts
  • Core Package
    • What is the Core Package?
    • Chat Commands
    • Inventory
    • Spawning Characters
    • Enable / Disable Core Features
  • Physics
    • Physics Settings
    • Physics Layers
  • Platform Services
    • Data Store
      • Locking
    • Cache Store
    • Leaderboards
    • Platform Inventory
    • Server Management
    • Server List
    • Server Transfers
    • Users
    • Parties
    • Matchmaking
    • External Services
  • CHARACTERS
    • Quick Configuration
    • Character Movement System
      • Character Movement Data
      • Character Movement Events
    • Character Camera
      • First Person Camera
      • Simple Usage
      • Camera Structure
      • Default Camera Modes
      • Disabling the Camera System
    • Character Animations
      • Character Blender Animations
      • Character Ragdoll
  • Accessories
    • Accessories Intro
    • Creating Accessories
    • Using Accessories
  • ANIMATIONS
    • Animation Events
  • Optimization
    • Live Game Profiler
    • Reducing Bundle Size
  • Game Settings
    • Game Visibility
  • Other
    • Project Status
    • FAQ
    • DataType Math
    • JS to Luau
    • Tags
    • Terrain
    • AirshipNetworkBehaviour
      • Lifecycle Events
      • ServerRpc
      • ObserversRpc
      • TargetRpc
    • VoxelWorld
      • Voxel World Getting Started
      • Voxel World Tips
      • Prefab Voxels
      • QuarterBlocks
    • Easy Helper Utils
      • Easy Motion
      • Easy Grid Align
      • Easy Look At
      • Easy Shake
      • Easy Destroy
Powered by GitBook
On this page
  • Listening for Key Presses
  • Disconnecting Listener
  • Polling for Keys Down
  • Sinking Key Events
  1. Input
  2. User Input

Keyboard

PreviousActionsNextMouse

Last updated 9 months ago

Keyboard API is useful for directly accessing keystrokes. If you want players to rebind your input use .

Listening for Key Presses

Use the OnKeyDown and OnKeyUp methods to listen for key events.

Keyboard.OnKeyDown(Key.E, (event) => {
    print("E key down");
});

Keyboard.OnKeyUp(Key.E, (event) => {
    print("E key up");
});

// Optional signal priority:
Keyboard.OnKeyDown(Key.E, (event) => {
    print("E key down, before the other one!");
}, SignalPriority.HIGH);

Disconnecting Listener

Keyboard listeners return a cleanup function. When you no longer need to listen to the key you can call the cleanup function to disconnect your callback.

// Listen for one press of "E" -- then disconnect
const disconnectKeyDownE = Keyboard.OnKeyDown(Key.E, (event) => {
    print("E key down");
    // Disconnect this listener
    disconnectKeyDownE();
});

Polling for Keys Down

To check if an individual key is down, call the IsKeyDown method. There are also two combination methods, IsEitherKeyDown and AreBothKeysDown.

// Check if single key is down:
if (Keyboard.IsKeyDown(Key.E)) print("E is down");

// Check if at least one of the two keys are down:
if (Keyboard.IsEitherKeyDown(Key.W, Key.UpArrow)) print("Up");

// Check if both keys are down:
if (Keyboard.AreBothKeysDown(Key.S, Key.LeftShift)) print("Save");

Sinking Key Events

It is possible to sink key input events, preventing the event from continuing on to other listeners.

To sink an event, use the SetCancelled event method. In cases where event sinking is occurring, it is best to also include the desired SignalPriority.

Keyboard.OnKeyDown(Key.E, (event) => {
    event.SetCancelled(true);
}, SignalPriority.HIGHEST);
Actions