0.10.7 • Published 1 day ago

@kmamal/sdl v0.10.7

Weekly downloads
-
License
MIT
Repository
github
Last release
1 day ago

@kmamal/sdl

Package Dependencies License: MIT

SDL bindings for Node.js. Provides window management, input events (keyboard, mouse, joysticks, controllers, sensors), audio playback and recording, clipboard manipulation, and battery status.

It should work on Linux, Mac, and Windows. Prebuilt binaries are available for x64 architectures, arm-based Macs, and Raspberry Pi.

Canvas, WebGL, and WebGPU

One goal of this project is to allow using Canvas, WebGL, and WebGPU without a browser. You can use the canvas package to render using the canvas API. For WebGL you can use @kmamal/gl and for WebGPU you can use @kmamal/gpu. Both WebGL and WebGPU support rendering directly to the window (without any intermediate buffer copying). Canvas still uses an intermediate buffer, but that might change in the future.

Installation

SDL is bundled along with the binaries so a separate installation is not necessary. This package is self-contained. Just run:

npm install @kmamal/sdl

(But if things go wrong do look over here)

Examples

"Hello, World!"

import sdl from '@kmamal/sdl'

const window = sdl.video.createWindow({ title: "Hello, World!" })
window.on('*', console.log)

Canvas

import sdl from '@kmamal/sdl'
import { createCanvas } from 'canvas'

// Setup
const window = sdl.video.createWindow({ title: "Canvas" })
const { pixelWidth: width, pixelHeight: height } = window
const canvas = createCanvas(width, height)
const ctx = canvas.getContext('2d')

// Clear screen to red
ctx.fillStyle = 'red'
ctx.fillRect(0, 0, width, height)

// Render to window
const buffer = canvas.toBuffer('raw')
window.render(width, height, width * 4, 'bgra32', buffer)

WebGL

import sdl from '@kmamal/sdl'
import createContext from '@kmamal/gl'

// Setup
const window = sdl.video.createWindow({ title: "WebGL", opengl: true })
const { pixelWidth: width, pixelHeight: height, native } = window
const gl = createContext(width, height, { window: native })

// Clear screen to red
gl.clearColor(1, 0, 0, 1)
gl.clear(gl.COLOR_BUFFER_BIT)

// Render to window
gl.swap()

WebGPU

import sdl from '@kmamal/sdl'
import gpu from '@kmamal/gpu'

// Setup
const window = sdl.video.createWindow({ title: "WebGPU", webgpu: true })
const instance = gpu.create([])
const adapter = await instance.requestAdapter()
const device = await adapter.requestDevice()
const renderer = gpu.renderGPUDeviceToWindow({ device, window })

// Clear screen to red
const commandEncoder = device.createCommandEncoder()
const renderPass = commandEncoder.beginRenderPass({
  colorAttachments: [
    {
      view: renderer.getCurrentTextureView(),
      clearValue: { r: 1.0, g: 0.0, b: 0.0, a: 1.0 },
      loadOp: 'clear',
      storeOp: 'store',
    },
  ],
})
renderPass.end()
device.queue.submit([ commandEncoder.finish() ])

// Render to window
renderer.swap()

More examples

Check the examples/ folder.

API Reference

Contents

sdl

sdl.info

  • <object>
    • version: <object>
      • compile: <object> The SDL version the bindings were compiled against.
        • major, minor, patch: <semver> The components of the version.
      • runtime: <object> The SDL version of the dynamic library the is loaded.
        • major, minor, patch: <semver> The components of the version.
    • platform: <string> The name of the platform we are running on. Possible values are: 'Linux', 'Windows', and 'Mac OS X'.
    • drivers: <object>
      • video: <object>
        • all: <string>[] A list of all video drivers.
        • current: <string>|<null> The video driver that is currently selected.
      • audio: <object>
        • all: <string>[] A list of all audio drivers.
        • current: <string>|<null> The audio driver that is currently selected.

This object is filled with the information produced during the initialization of SDL. All the values will remain constant throughout the execution of the program. If you want to initialize SDL with drivers other than the default ones, you can do so via its environment variables.

Note that the current video or audio driver can be null. This can happen on systems that don't have any compatible devices, such as on a CI pipeline.

Sample data for Ubuntu:

{
  version: {
    compile: { major: 2, minor: 0, patch: 10 },
    runtime: { major: 2, minor: 0, patch: 10 },
  },
  platform: 'Linux',
  drivers: {
    video: {
      all: [ 'x11', 'wayland', 'dummy' ],
      current: 'x11',
    },
    audio: {
      all: [ 'pulseaudio', 'alsa', 'sndio', 'dsp', 'disk', 'dummy' ],
      current: 'pulseaudio',
    },
  },
}

sdl.video

Image data

There are 3 places in the API where you will need to provide an image to the library:

All three of these functions accept the image as a series of arguments:

  • width: <number> The width of the image in pixels.
  • height: <number> The height of the image in pixels.
  • stride: <number> How many bytes each row of the image takes up in the buffer. This is usually equal to width * bytesPerPixel, but can be larger if the rows of the buffer are padded to always be some multiple of bytes.
  • format:<PixelFormat> The binary representation of the data in the buffer.
  • buffer: <Buffer> Holds the actual pixel data for the image, in the format and layout specified by all the above arguments.

So for example, to fill the window with a red+green gradient you could do:

const { pixelWidth: width, pixelHeight: height } = window
const stride = width * 4
const buffer = Buffer.alloc(stride * height)

let offset = 0
for (let i = 0; i < height; i++) {
  for (let j = 0; j < width; j++) {
    buffer[offset++] = Math.floor(256 * i / height) // R
    buffer[offset++] = Math.floor(256 * j / width)  // G
    buffer[offset++] = 0                            // B
    buffer[offset++] = 255                          // A
  }
}

window.render(width, height, stride, 'rgba32', buffer)

High-DPI

On a high-dpi display, windows have more pixels that their width and height would indicate. On such systems width and height (and all other measurements such as x and y) are in "points". Points are abstract and don't have to correspond to pixels. If you need to know a window's width and height in pixels, you should use the pixelWidth and pixelHeight properties. You should be doing this always, since you don't know beforehand if your program will be running on a high-dpi system.

Pixel formats

String values used to represent how the pixels of an image are stored in a Buffer.

ValueCorresponding SDL_PixelFormatEnumComment
'rgb332'SDL_PIXELFORMAT_RGB332
'rgb444'SDL_PIXELFORMAT_RGB444
'rgb555'SDL_PIXELFORMAT_RGB555
'bgr555'SDL_PIXELFORMAT_BGR555
'argb4444'SDL_PIXELFORMAT_ARGB4444
'rgba4444'SDL_PIXELFORMAT_RGBA4444
'abgr4444'SDL_PIXELFORMAT_ABGR4444
'bgra4444'SDL_PIXELFORMAT_BGRA4444
'argb1555'SDL_PIXELFORMAT_ARGB1555
'rgba5551'SDL_PIXELFORMAT_RGBA5551
'abgr1555'SDL_PIXELFORMAT_ABGR1555
'bgra5551'SDL_PIXELFORMAT_BGRA5551
'rgb565'SDL_PIXELFORMAT_RGB565
'bgr565'SDL_PIXELFORMAT_BGR565
'rgb24'SDL_PIXELFORMAT_RGB24
'bgr24'SDL_PIXELFORMAT_BGR24
'rgb888'SDL_PIXELFORMAT_RGB888
'rgbx8888'SDL_PIXELFORMAT_RGBX8888
'bgr888'SDL_PIXELFORMAT_BGR888
'bgrx8888'SDL_PIXELFORMAT_BGRX8888
'argb8888'SDL_PIXELFORMAT_ARGB8888
'rgba8888'SDL_PIXELFORMAT_RGBA8888
'abgr8888'SDL_PIXELFORMAT_ABGR8888
'bgra8888'SDL_PIXELFORMAT_BGRA8888
'argb2101010'SDL_PIXELFORMAT_ARGB2101010
'rgba32'SDL_PIXELFORMAT_RGBA32alias for 'rgba8888' on big endian machines and for 'abgr8888' on little endian machines
'argb32'SDL_PIXELFORMAT_ARGB32alias for 'argb8888' on big endian machines and for 'bgra8888' on little endian machines
'bgra32'SDL_PIXELFORMAT_BGRA32alias for 'bgra8888' on big endian machines and for 'argb8888' on little endian machines
'abgr32'SDL_PIXELFORMAT_ABGR32alias for 'abgr8888' on big endian machines and for 'rgba8888' on little endian machines
'yv12'SDL_PIXELFORMAT_YV12planar mode: Y + V + U (3 planes)
'iyuv'SDL_PIXELFORMAT_IYUVplanar mode: Y + U + V (3 planes)
'yuy2'SDL_PIXELFORMAT_YUY2packed mode: Y0+U0+Y1+V0 (1 plane)
'uyvy'SDL_PIXELFORMAT_UYVYpacked mode: U0+Y0+V0+Y1 (1 plane)
'yvyu'SDL_PIXELFORMAT_YVYUpacked mode: Y0+V0+Y1+U0 (1 plane)
'nv12'SDL_PIXELFORMAT_NV12planar mode: Y + U/V interleaved (2 planes)
'nv21'SDL_PIXELFORMAT_NV21planar mode: Y + V/U interleaved (2 planes)

Event: 'displayAdd'

  • device: <object>: An object from sdl.video.displays indicating the display that caused the event.

Fired when a display is added to the system. Check sdl.video.displays to get the new list of displays.

Event: 'displayRemove'

  • device: <object>: An object from sdl.video.displays indicating the display that caused the event.

Fired when a display is removed from the system. Check sdl.video.displays to get the new list of displays.

Event: 'displayOrient'

  • device: <object>: An object from sdl.video.displays indicating the display that caused the event.

Fired when a display changes orientation. Check sdl.video.displays to get the new list of displays.

sdl.video.displays

  • <object>[]
    • name: <string> The name of the display.
    • format:<PixelFormat> The pixel format of the display.
    • frequency: <number> The refresh rate of the display.
    • geometry: <object> The desktop region represented by the display.
      • x, y, width, height: <Rect> The position and size of the display's geometry.
    • usable: <object> Similar to geometry, but excludes areas taken up by the OS or window manager such as menus, docks, e.t.c.
      • x, y, width, height: <Rect> The position and size of the display's usable region.
    • dpi: <object>|<null> Return pixel density for the display in dots/pixels-per-inch units. Might be null on some devices if DPI info can't be retrieved.
      • horizontal: <number> The horizontal density.
      • vertical: <number> The vertical density.
      • diagonal: <number> The diagonal density.

A list of all detected displays. Sample output for two side-to-side monitors is below. Notice how the geometries don't overlap:

[
  {
    name: '0',
    format: 'rgb888',
    frequency: 60,
    geometry: { x: 0, y: 0, width: 1920, height: 1080 },
    usable: { x: 0, y: 27, width: 1920, height: 1053 },
    dpi: { horizontal: 141.76, vertical: 142.13, diagonal: 141.85 }
  },
  {
    name: '1',
    format: 'rgb888',
    frequency: 60,
    geometry: { x: 1920, y: 0, width: 1920, height: 1080 },
    usable: { x: 1920, y: 27, width: 1920, height: 1053 },
    dpi: { horizontal: 141.76, vertical: 142.13, diagonal: 141.85 }
  },
]

sdl.video.windows

A list of all open windows.

sdl.video.focused

The window that has the current keyboard focus, or null if no window has the keyboard focus.

sdl.video.hovered

The window that the mouse is hovered over, or null if the mouse is not over a window.

sdl.video.createWindow(options)

  • options: <object>
    • title: <string> Will appear in the window's title bar. Default: ''
    • display: <number> An object from sdl.video.displays to specify in which display the window will appear (if you have multiple displays). Default: sdl.video.displays[0]
    • x: <number> The x position in which the window will appear relative to the screen, or null for centered. Default: null
    • y: <number> The y position in which the window will appear relative to the screen, or null for centered. Default: null
    • width: <number> The width of the window. Default: 640
    • height: <number> The height of the window. Default: 480
    • visible: <boolean> Set to false to create a hidden window that will only be shown when you call window.show(). Default: true
    • fullscreen: <boolean> Set to true to create the window in fullscreen mode. Default: false
    • resizable: <boolean> Set to true to allow resizing the window by dragging its borders. Default: false
    • borderless: <boolean> Set to true to completely hide the window's borders and title bar. Default: false
    • alwaysOnTop: <boolean> Set to true to always show this window above others. Default: false
    • accelerated: <boolean> Set to false to disable hardware accelerated rendering. Default: true
    • vsync: <boolean> Set to false to disable frame rate synchronization. Default: true
    • opengl: <boolean> Set to true to create an OpenGL-compatible window (for use with @kmamal/gl). Default: false
    • webgpu: <boolean> Set to true to create an WebGPU-compatible window (for use with @kmamal/gpu). Default: false
    • skipTaskbar: <boolean> X11 only. Set to true to not add this window to the taskbar. Default: false
    • popupMenu: <boolean> X11 only. Set to true to treat this window like a popup menu. Default: false
    • tooltip: <boolean> X11 only. Set to true to treat this window like a tooltip. Default: false
    • utility: <boolean> X11 only. Set to true to treat this window like a utility window. Default: false
  • Returns: <Window> an object representing the new window.

Creates a new window.

The following restrictions apply:

  • If you specify the display option, you can't also specify the x or y options, and vice-versa.
  • The resizable and borderless options are mutually exclusive.
  • The opengl and webgpu options are mutually exclusive.
  • The vsync option only applies to windows that are also accelerated.
  • The accelerated and vsync options have no effect if either opengl or webgpu is also specified.

If you set the opengl or webgpu options, then you can only render to the window with OpenGL/WebGPU calls. Calls to render() will fail.

class Window

This class is not directly exposed by the API so you can't use it with the new operator. Instead, objects returned by sdl.video.createWindow() are of this type.

Event: 'show'

Fired when a window becomes visible.

Event: 'hide'

Fired when a window becomes hidden.

Event: 'expose'

Fired when a window becomes exposed and should be redrawn.

Event: 'minimize'

Fired when a window becomes minimized.

Event: 'maximize'

Fired when a window becomes maximized.

Event: 'restore'

Fired when a window gets restored.

Event: 'move'

  • x: <number> The window's new x position, relative to the screen.
  • y: <number> The window's new y position, relative to the screen.

Fired when the window changes position.

Event: 'resize'

  • width: <number> The window's new width.
  • height: <number> The window's new height.
  • pixelWidth: <number> The window's new width in pixels. See high-dpi.
  • pixelHeight: <number> The window's new height in pixels. See high-dpi.

Fired when the window changes size.

Event: 'focus'

Fired when a window gains the keyboard focus.

Event: 'blur'

Fired when a window loses the keyboard focus.

Event: 'hover'

Fired when the mouse enters the window.

Event: 'leave'

Fired when the mouse leaves the window.

Event: 'beforeClose'

  • prevent: <function (void) => void> Call this to prevent the window from closing.

Fired to indicate that the user has requested the window to close (usually by clicking the "x" button). If you need to display any confirmation dialogs you should call event.prevent() and handle destruction manually. If prevent is not called, then this event will be followed by a 'close' event.

Event: 'close'

Indicates that the window is about to be destroyed. Handle any cleanup here.

Event: 'keyDown'

  • scancode:<Scancode> The scancode of the key that caused the event.
  • key:<Key>|<null> The virtual key that caused the event, or null if the physical key does not correspond to any virtual key.
  • repeat: <boolean> Is true if the event was generated by holding down a key for a long time.
  • shift: <boolean> Is true if the Shift key was pressed when the event was generated.
  • ctrl: <boolean> Is true if the Ctrl key was pressed when the event was generated.
  • alt: <boolean> Is true if the Alt key was pressed when the event was generated.
  • super: <boolean> Is true if the "Windows" key was pressed when the event was generated.
  • altgr: <boolean> Is true if the AltGr key was pressed when the event was generated.
  • capslock: <boolean> Is true if CapsLock was active when the event was generated.
  • numlock: <boolean> Is true if NumLock was active when the event was generated.

Fired when a key is pressed, and will also be fired repeatedly afterwards if the key is held down.

Event: 'keyUp'

  • scancode:<Scancode> The scancode of the key that caused the event.
  • key:<Key>|<null> The virtual key that caused the event, or null if the physical key does not correspond to any virtual key.
  • shift: <boolean> Is true if the Shift key was pressed when the event was generated.
  • ctrl: <boolean> Is true if the Ctrl key was pressed when the event was generated.
  • alt: <boolean> Is true if the Alt key was pressed when the event was generated.
  • super: <boolean> Is true if the "Windows" key was pressed when the event was generated.
  • altgr: <boolean> Is true if the AltGr key was pressed when the event was generated.
  • capslock: <boolean> Is true if CapsLock was active when the event was generated.
  • numlock: <boolean> Is true if NumLock was active when the event was generated.

Fired when a key is released.

Event: 'textInput'

  • text: <string> The unicode representation of the character that was entered.

Fired when the user enters text via the keyboard.

Event: 'mouseButtonDown'

  • x: <number> The mouse's x position when the event happened, relative to the window.
  • y: <number> The mouse's y position when the event happened, relative to the window.
  • touch: <boolean> Will be true if the event was caused by a touch event.
  • button:<sdl.mouse.BUTTON> The button that was pressed.

Fired when a mouse button is pressed.

Event: 'mouseButtonUp'

  • x: <number> The mouse's x position when the event happened, relative to the window.
  • y: <number> The mouse's y position when the event happened, relative to the window.
  • touch: <boolean> Will be true if the event was caused by a touch event.
  • button:<sdl.mouse.BUTTON> The button that was released.

Fired when a mouse button is released.

Event: 'mouseMove'

  • x: <number> The mouse's x position when the event happened, relative to the window.
  • y: <number> The mouse's y position when the event happened, relative to the window.
  • touch: <boolean> Will be true if the event was caused by a touch event.

Fired when the mouse moves.

Event: 'mouseWheel'

  • x: <number> The mouse's x position when the event happened, relative to the window.
  • y: <number> The mouse's y position when the event happened, relative to the window.
  • touch: <boolean> Will be true if the event was caused by a touch event.
  • dx: <number> The wheel's x movement, relative to its last position.
  • dy: <number> The wheel's y movement, relative to its last position.
  • flipped: <boolean> Will be true if the underlying platform reverses the mouse wheel's scroll direction. Multiply dx and dy by -1 to get the correct values.

Fired when the mouse wheel is scrolled.

Event: 'dropBegin'

When dropping a set of items onto a window, first the 'dropBegin' event will be fired, then a number of 'dropText' and/or 'dropFile' events will be fired, corresponding to the contents of the drop, then finally the 'dropComplete' event will be fired.

Event: 'dropText'

  • text: <string>: The text that was dropped onto the window.

Fired when one of the drops is a text item.

Event: 'dropFile'

  • file: <string>: The path to the file that was dropped onto the window.

Fired when one of the drops is a file.

Event: 'dropComplete'

Fired after a set of items has been dropped on a window.

window.id

  • <number>

A unique identifier for the window.

window.title

  • <string>

The text that appears in the window's title bar.

window.setTitle(title)

  • title: <string>: The new title.

Changes the text that appears in the window's title bar.

window.x

  • <number>

The window's x position, relative to the screen.

window.y

  • <number>

The window's y position, relative to the screen.

window.setPosition(x, y)

  • x: <number>: The new x position, relative to the screen.
  • y: <number>: The new y position, relative to the screen.

Moves the window to a new position on the screen.

window.width

  • <number>

The window's width.

window.height

  • <number>

The window's height.

window.pixelWidth

  • <number>

The window's width in pixels. This will be larger than width on high-dpi displays.

window.pixelHeight

  • <number>

The window's height in pixels. This will be larger than height on high-dpi displays.

window.setSize(width, height)

  • width: <number>: The new width.
  • height: <number>: The new height.

Changes the size of the window.

window.visible

  • <boolean>

Will be true if the window is visible.

window.show(show)

  • show: <boolean> Set to true to make the window visible, false to hide it. Default: true

Shows or hides the window.

window.hide()

Equivalent to window.show(false).

window.fullscreen

  • <boolean>

Will be true if the window is fullscreen. A fullscreen window is displayed over the entire screen.

window.setFullscreen(fullscreen)

  • fullscreen: <boolean> The new value of the property.

Changes the window's fullscreen property.

window.resizable

  • <boolean>

Will be true if the window is resizable. A resizable window can be resized by dragging it's borders.

window.setResizable(resizable)

  • resizable: <boolean> The new value of the property.

Changes the window's resizable property.

window.borderless

  • <boolean>

Will be true if the window is borderless. A borderless window has no borders or title bar.

window.setBorderless(borderless)

  • borderless: <boolean> The new value of the property.

Changes the window's borderless property.

window.alwaysOnTop

  • <boolean>

Will be true if the window was created with alwaysOnTop: true. Such a window will always be shown above other windows.

window.accelerated

  • <boolean>

Will be true if the window is using hardware accelerated rendering.

window.setAccelerated(accelerated)

  • accelerated: <boolean> The new value of the property.

Changes the window's accelerated property.

If you have set the opengl or webgpu options, then calls to this function will fail.

window.vsync

  • <boolean>

Will be true if the window is using vsync. A window with vsync enabled will have its frame rate synchronized to the display's refresh rate to prevent tearing. Note that vsync can only be used if that window is also accelerated

window.setVsync(vsync)

  • vsync: <boolean> The new value of the property.

Changes the window's vsync property.

If you have set the opengl or webgpu options, then calls to this function will fail.

window.opengl

  • <boolean>

Will be true if the window was created in OpenGl mode. In OpenGL mode, you can only render to the window with OpenGL calls. Calls to render() will fail.

window.webgpu

  • <boolean>

Will be true if the window was created in WebGPU mode. In WebGPU mode, you can only render to the window with WebGPU calls. Calls to render() will fail.

window.native

  • <any>

Holds a copy of the native (platform-specific) representation of the window. Only used for passing to @kmamal/gl or @kmamal/gpu.

window.maximized

  • <boolean>

Will be true if the window is maximized.

window.maximize()

Maximizes the window.

window.minimized

  • <boolean>

Will be true if the window is minimized.

window.minimize()

Minimizes the window.

window.restore()

Restores the window so it's neither minimized nor maximized.

window.focused

  • <boolean>

Will be true if the window has keyboard input.

window.focus()

Gives the window the keyboard focus.

window.hovered

  • <boolean>

Will be true if the mouse is over the window.

window.skipTaskbar

  • <boolean>

X11 only. Will be true if the window was created with skipTaskbar: true. Such a window will not be added to the taskbar.

window.popupMenu

  • <boolean>

X11 only. Will be true if the window was created with popupMenu: true. Such a window will always be treated as a popup menu.

window.tooltip

  • <boolean>

X11 only. Will be true if the window was created with tooltip: true. Such a window will always be treated as a tooltip.

window.utility

  • <boolean>

X11 only. Will be true if the window was created with utility: true. Such a window will always be treated as a utility window.

window.render(width, height, stride, format, buffer)

  • width, height, stride, format, buffer:<Image> The image to display on the window.

Displays an image in the window. The provided image will be stretched over the entire window.

If you set the opengl or webgpu options, then you can only render to the window with OpenGL/WebGPU calls. Calls to render() will fail.

window.setIcon(width, height, stride, format, buffer)

  • width, height, stride, format, buffer:<Image> The image to display as the icon of the window.

Set's the window's icon, usually displayed in the title bar and the taskbar.

window.flash(untilFocused)

  • untilFocused: <boolean> Whether to keep flashing the window until the user focuses it. Default: false

Flash the window briefly to get attention. If untilFocused is set, the window will flash until the user focuses it.

window.stopFlashing()

Stop the window from flashing.

window.destroyed

  • <boolean>

Will be true if the window is destroyed. A destroyed window object should not be used any further.

window.destroy()

Destroys the window.

sdl.keyboard

There are three levels at which you can deal with the keyboard: physical keys (scancodes), virtual keys (keys), and text ('textInput' events).

On the physical level, each of the physical keys corresponds to a number: the key's scancode. For any given keyboard, the same key will always produce the same scancode. If your application cares about the layout of the keyboard (for example using the "WASD" keys as a substitute for arrow keys), then you should handle key events at this level using the scancode property of 'keyDown' and 'keyUp' events.

For the most part it's better to treat scancode values as arbitrary/meaningless, but SDL does provide a scancode enumeration with values based on the USB usage page standard so you should be able to derive some meaning from the scancodes if your keyboard is compatible.

More commonly, you don't care about the physical key itself but about the "meaning" associated with each key: the character that it produces ("a", "b", "@", " ", .e.t.c) or the function that it corresponds to ("Esc", "F4", "Ctrl", e.t.c.). Your operating system provides a "keyboard mapping" that associates physical keys with their corresponding meaning. Changing the keyboard mapping (for example by changing the language from English to German) will also change the corresponding meaning for each key (in the English-German example: the "y" and "z" keys will be switched). These meanings are represented as virtual key strings. If your application cares about the meaning associated with individual keys then you should handle key events at this level using the key property of 'keyDown' and 'keyUp' events.

Note that not all physical keys correspond to a well-defined meaning and thus don't have a virtual key value associated with them. The key events for these keys will have a null value for the key property.

But sometimes the application doesn't care about individual keys at all, but about the resulting text that the user is entering. Consider for example what happens when a user on a Greek keyboard layout enters an accent mark "´" followed by the letter "α" to produce the character "ά": Two keys were pressed, but only a single character was produced. Trying to handle text input by manually translating key presses to text is not a very viable solution. It's better to let the OS handle all the text logic, and get the final text by handling the rasulting ('textInput') events.

Virtual keys

String values used to represent virtual keys in the context of the current keyboard mapping. Note that some keys do not correspond to any virtual key. A Key can be either one of the values below or any unicode character. Keys that produce characters are represented by that character. All others are represented by one of these values:

'&&', '+/-', '||', '00', '000', 'again', 'alt', 'altErase', 'app1', 'app2', 'application', 'audioFastForward', 'audioMute', 'audioNext', 'audioPlay', 'audioPrev', 'audioRewind', 'audioStop', 'back', 'backspace', 'binary', 'bookmarks', 'brightnessDown', 'brightnessUp', 'calculator', 'cancel', 'capsLock', 'clear', 'clearEntry', 'computer', 'copy', 'crSel', 'ctrl', 'currencySubUnit', 'currencyUnit', 'cut', 'decimal', 'decimalSeparator', 'delete', 'displaySwitch', 'down', 'eject', 'end', 'enter', 'escape', 'execute', 'exSel', 'f1', 'f2', 'f3', 'f4', 'f5', 'f6', 'f7', 'f8', 'f9', 'f10', 'f11', 'f12', 'f13', 'f14', 'f15', 'f16', 'f17', 'f18', 'f19', 'f20', 'f21', 'f22', 'f23', 'f24', 'find', 'forward', 'gui', 'help', 'hexadecimal', 'home', 'illumDown', 'illumToggle', 'illumUp', 'insert', 'left', 'mail', 'mediaSelect', 'memAdd', 'memClear', 'memDivide', 'memMultiply', 'memRecall', 'memStore', 'memSubtract', 'menu', 'modeSwitch', 'mute', 'numlock', 'octal', 'oper', 'out', 'pageDown', 'pageUp', 'paste', 'pause', 'power', 'printScreen', 'prior', 'refresh', 'return', 'right', 'scrollLock', 'search', 'select', 'separator', 'shift', 'sleep', 'space', 'stop', 'sysReq', 'tab', 'thousandsSeparator', 'undo', 'up', 'volumeDown', 'volumeUp', 'www', 'xor'.

Enum: SCANCODE

Used to represent physical keys on the keyboard. The same key will always produce the same scancode. Values are based on the USB usage page standard.

ValueCorresponding SDL_ScancodeComment
sdl.keyboard.SCANCODE.ASDL_SCANCODE_A
sdl.keyboard.SCANCODE.BSDL_SCANCODE_B
sdl.keyboard.SCANCODE.CSDL_SCANCODE_C
sdl.keyboard.SCANCODE.DSDL_SCANCODE_D
sdl.keyboard.SCANCODE.ESDL_SCANCODE_E
sdl.keyboard.SCANCODE.FSDL_SCANCODE_F
sdl.keyboard.SCANCODE.GSDL_SCANCODE_G
sdl.keyboard.SCANCODE.HSDL_SCANCODE_H
sdl.keyboard.SCANCODE.ISDL_SCANCODE_I
sdl.keyboard.SCANCODE.JSDL_SCANCODE_J
sdl.keyboard.SCANCODE.KSDL_SCANCODE_K
sdl.keyboard.SCANCODE.LSDL_SCANCODE_L
sdl.keyboard.SCANCODE.MSDL_SCANCODE_M
sdl.keyboard.SCANCODE.NSDL_SCANCODE_N
sdl.keyboard.SCANCODE.OSDL_SCANCODE_O
sdl.keyboard.SCANCODE.PSDL_SCANCODE_P
sdl.keyboard.SCANCODE.QSDL_SCANCODE_Q
sdl.keyboard.SCANCODE.RSDL_SCANCODE_R
sdl.keyboard.SCANCODE.SSDL_SCANCODE_S
sdl.keyboard.SCANCODE.TSDL_SCANCODE_T
sdl.keyboard.SCANCODE.USDL_SCANCODE_U
sdl.keyboard.SCANCODE.VSDL_SCANCODE_V
sdl.keyboard.SCANCODE.WSDL_SCANCODE_W
sdl.keyboard.SCANCODE.XSDL_SCANCODE_X
sdl.keyboard.SCANCODE.YSDL_SCANCODE_Y
sdl.keyboard.SCANCODE.ZSDL_SCANCODE_Z
sdl.keyboard.SCANCODE.1SDL_SCANCODE_1
sdl.keyboard.SCANCODE.2SDL_SCANCODE_2
sdl.keyboard.SCANCODE.3SDL_SCANCODE_3
sdl.keyboard.SCANCODE.4SDL_SCANCODE_4
sdl.keyboard.SCANCODE.5SDL_SCANCODE_5
sdl.keyboard.SCANCODE.6SDL_SCANCODE_6
sdl.keyboard.SCANCODE.7SDL_SCANCODE_7
sdl.keyboard.SCANCODE.8SDL_SCANCODE_8
sdl.keyboard.SCANCODE.9SDL_SCANCODE_9
sdl.keyboard.SCANCODE.0SDL_SCANCODE_0
sdl.keyboard.SCANCODE.RETURNSDL_SCANCODE_RETURN
sdl.keyboard.SCANCODE.ESCAPESDL_SCANCODE_ESCAPE
sdl.keyboard.SCANCODE.BACKSPACESDL_SCANCODE_BACKSPACE
sdl.keyboard.SCANCODE.TABSDL_SCANCODE_TAB
sdl.keyboard.SCANCODE.SPACESDL_SCANCODE_SPACE
sdl.keyboard.SCANCODE.MINUSSDL_SCANCODE_MINUS
sdl.keyboard.SCANCODE.EQUALSSDL_SCANCODE_EQUALS
sdl.keyboard.SCANCODE.LEFTBRACKETSDL_SCANCODE_LEFTBRACKET
sdl.keyboard.SCANCODE.RIGHTBRACKETSDL_SCANCODE_RIGHTBRACKET
sdl.keyboard.SCANCODE.BACKSLASHSDL_SCANCODE_BACKSLASHLocated at the lower left of the return key on ISO keyboards and at the right end of the QWERTY row on ANSI keyboards. Produces REVERSE SOLIDUS (backslash) and VERTICAL LINE in a US layout, REVERSE SOLIDUS and VERTICAL LINE in a UK Mac layout, NUMBER SIGN and TILDE in a UK Windows layout, DOLLAR SIGN and POUND SIGN in a Swiss German layout, NUMBER SIGN and APOSTROPHE in a German layout, GRAVE ACCENT and POUND SIGN in a French Mac layout, and ASTERISK and MICRO SIGN in a French Windows layout.
sdl.keyboard.SCANCODE.NONUSHASHSDL_SCANCODE_NONUSHASHISO USB keyboards actually use this code instead of 49 for the same key, but all OSes I've seen treat the two codes identically. So, as an implementor, unless your keyboard generates both of those codes and your OS treats them differently, you should generate SDL_SCANCODE_BACKSLASH instead of this code. As a user, you should not rely on this code because SDL will never generate it with most (all?) keyboards.
sdl.keyboard.SCANCODE.SEMICOLONSDL_SCANCODE_SEMICOLON
sdl.keyboard.SCANCODE.APOSTROPHESDL_SCANCODE_APOSTROPHE
sdl.keyboard.SCANCODE.GRAVESDL_SCANCODE_GRAVELocated in the top left corner (on both ANSI and ISO keyboards). Produces GRAVE ACCENT and TILDE in a US Windows layout and in US and UK Mac layouts on ANSI keyboards, GRAVE ACCENT and NOT SIGN in a UK Windows layout, SECTION SIGN and PLUS-MINUS SIGN in US and UK Mac layouts on ISO keyboards, SECTION SIGN and DEGREE SIGN in a Swiss German layout (Mac: only on ISO keyboards), CIRCUMFLEX ACCENT and DEGREE SIGN in a German layout (Mac: only on ISO keyboards), SUPERSCRIPT TWO and TILDE in a French Windows layout, COMMERCIAL AT and NUMBER SIGN in a French Mac layout on ISO keyboards, and LESS-THAN SIGN and GREATER-THAN SIGN in a Swiss German, German, or French Mac layout on ANSI keyboards.
sdl.keyboard.SCANCODE.COMMASDL_SCANCODE_COMMA
sdl.keyboard.SCANCODE.PERIODSDL_SCANCODE_PERIOD
sdl.keyboard.SCANCODE.SLASHSDL_SCANCODE_SLASH
sdl.keyboard.SCANCODE.CAPSLOCKSDL_SCANCODE_CAPSLOCK
sdl.keyboard.SCANCODE.F1SDL_SCANCODE_F1
sdl.keyboard.SCANCODE.F2SDL_SCANCODE_F2
sdl.keyboard.SCANCODE.F3SDL_SCANCODE_F3
sdl.keyboard.SCANCODE.F4SDL_SCANCODE_F4
sdl.keyboard.SCANCODE.F5SDL_SCANCODE_F5
sdl.keyboard.SCANCODE.F6SDL_SCANCODE_F6
sdl.keyboard.SCANCODE.F7SDL_SCANCODE_F7
sdl.keyboard.SCANCODE.F8SDL_SCANCODE_F8
sdl.keyboard.SCANCODE.F9SDL_SCANCODE_F9
sdl.keyboard.SCANCODE.F10SDL_SCANCODE_F10
sdl.keyboard.SCANCODE.F11SDL_SCANCODE_F11
sdl.keyboard.SCANCODE.F12SDL_SCANCODE_F12
sdl.keyboard.SCANCODE.PRINTSCREENSDL_SCANCODE_PRINTSCREEN
sdl.keyboard.SCANCODE.SCROLLLOCKSDL_SCANCODE_SCROLLLOCK
sdl.keyboard.SCANCODE.PAUSESDL_SCANCODE_PAUSE
sdl.keyboard.SCANCODE.INSERTSDL_SCANCODE_INSERTinsert on PC, help on some Mac keyboards
sdl.keyboard.SCANCODE.HOMESDL_SCANCODE_HOME
sdl.keyboard.SCANCODE.PAGEUPSDL_SCANCODE_PAGEUP
sdl.keyboard.SCANCODE.DELETESDL_SCANCODE_DELETE
sdl.keyboard.SCANCODE.ENDSDL_SCANCODE_END
sdl.keyboard.SCANCODE.PAGEDOWNSDL_SCANCODE_PAGEDOWN
sdl.keyboard.SCANCODE.RIGHTSDL_SCANCODE_RIGHT
sdl.keyboard.SCANCODE.LEFTSDL_SCANCODE_LEFT
sdl.keyboard.SCANCODE.DOWNSDL_SCANCODE_DOWN
sdl.keyboard.SCANCODE.UPSDL_SCANCODE_UP
sdl.keyboard.SCANCODE.NUMLOCKCLEARSDL_SCANCODE_NUMLOCKCLEARnum lock on PC, clear on Mac keyboards
sdl.keyboard.SCANCODE.KP_DIVIDESDL_SCANCODE_KP_DIVIDE
sdl.keyboard.SCANCODE.KP_MULTIPLYSDL_SCANCODE_KP_MULTIPLY
sdl.keyboard.SCANCODE.KP_MINUSSDL_SCANCODE_KP_MINUS
sdl.keyboard.SCANCODE.KP_PLUSSDL_SCANCODE_KP_PLUS
sdl.keyboard.SCANCODE.KP_ENTERSDL_SCANCODE_KP_ENTER
sdl.keyboard.SCANCODE.KP_1SDL_SCANCODE_KP_1
sdl.keyboard.SCANCODE.KP_2SDL_SCANCODE_KP_2
sdl.keyboard.SCANCODE.KP_3SDL_SCANCODE_KP_3
sdl.keyboard.SCANCODE.KP_4SDL_SCANCODE_KP_4
sdl.keyboard.SCANCODE.KP_5SDL_SCANCODE_KP_5
sdl.keyboard.SCANCODE.KP_6SDL_SCANCODE_KP_6
sdl.keyboard.SCANCODE.KP_7SDL_SCANCODE_KP_7
sdl.keyboard.SCANCODE.KP_8SDL_SCANCODE_KP_8
sdl.keyboard.SCANCODE.KP_9SDL_SCANCODE_KP_9
sdl.keyboard.SCANCODE.KP_0SDL_SCANCODE_KP_0
sdl.keyboard.SCANCODE.KP_PERIODSDL_SCANCODE_KP_PERIOD
sdl.keyboard.SCANCODE.NONUSBACKSLASHSDL_SCANCODE_NONUSBACKSLASHThis is the additional key that ISO keyboards have over ANSI ones, located between left shift and Y. Produces GRAVE ACCENT and TILDE in a US or UK Mac layout, REVERSE SOLIDUS (backslash) and VERTICAL LINE in a US or UK Windows layout, and LESS-THAN SIGN and GREATER-THAN SIGN in a Swiss German, German, or French layout.
sdl.keyboard.SCANCODE.APPLICATIONSDL_SCANCODE_APPLICATIONwindows contextual menu, compose
sdl.keyboard.SCANCODE.POWERSDL_SCANCODE_POWERThe USB document says this is a status flag, not a physical key - but some Mac keyboards do have a power key.
sdl.keyboard.SCANCODE.KP_EQUALSSDL_SCANCODE_KP_EQUALS
sdl.keyboard.SCANCODE.F13SDL_SCANCODE_F13
sdl.keyboard.SCANCODE.F14SDL_SCANCODE_F14
sdl.keyboard.SCANCODE.F15SDL_SCANCODE_F15
sdl.keyboard.SCANCODE.F16SDL_SCANCODE_F16
sdl.keyboard.SCANCODE.F17SDL_SCANCODE_F17
sdl.keyboard.SCANCODE.F18SDL_SCANCODE_F18
sdl.keyboard.SCANCODE.F19SDL_SCANCODE_F19
sdl.keyboard.SCANCODE.F20SDL_SCANCODE_F20
sdl.keyboard.SCANCODE.F21SDL_SCANCODE_F21
sdl.keyboard.SCANCODE.F22SDL_SCANCODE_F22
sdl.keyboard.SCANCODE.F23SDL_SCANCODE_F23
sdl.keyboard.SCANCODE.F24SDL_SCANCODE_F24
sdl.keyboard.SCANCODE.EXECUTESDL_SCANCODE_EXECUTE
sdl.keyboard.SCANCODE.HELPSDL_SCANCODE_HELP
sdl.keyboard.SCANCODE.MENUSDL_SCANCODE_MENU
sdl.keyboard.SCANCODE.SELECTSDL_SCANCODE_SELECT
sdl.keyboard.SCANCODE.STOPSDL_SCANCODE_STOP
sdl.keyboard.SCANCODE.AGAINSDL_SCANCODE_AGAINredo
sdl.keyboard.SCANCODE.UNDOSDL_SCANCODE_UNDO
sdl.keyboard.SCANCODE.CUTSDL_SCANCODE_CUT
sdl.keyboard.SCANCODE.COPYSDL_SCANCODE_COPY
sdl.keyboard.SCANCODE.PASTESDL_SCANCODE_PASTE
sdl.keyboard.SCANCODE.FINDSDL_SCANCODE_FIND
sdl.keyboard.SCANCODE.MUTESDL_SCANCODE_MUTE
sdl.keyboard.SCANCODE.VOLUMEUPSDL_SCANCODE_VOLUMEUP
sdl.keyboard.SCANCODE.VOLUMEDOWNSDL_SCANCODE_VOLUMEDOWN
sdl.keyboard.SCANCODE.KP_COMMASDL_SCANCODE_KP_COMMA
sdl.keyboard.SCANCODE.KP_EQUALSAS400SDL_SCANCODE_KP_EQUALSAS400
sdl.keyboard.SCANCODE.INTERNATIONAL1SDL_SCANCODE_INTERNATIONAL1used on Asian keyboards, see footnotes in USB doc
sdl.keyboard.SCANCODE.INTERNATIONAL2SDL_SCANCODE_INTERNATIONAL2
sdl.keyboard.SCANCODE.INTERNATIONAL3SDL_SCANCODE_INTERNATIONAL3Yen
sdl.keyboard.SCANCODE.INTERNATIONAL4SDL_SCANCODE_INTERNATIONAL4
sdl.keyboard.SCANCODE.INTERNATIONAL5SDL_SCANCODE_INTERNATIONAL5
sdl.keyboard.SCANCODE.INTERNATIONAL6SDL_SCANCODE_INTERNATIONAL6
sdl.keyboard.SCANCODE.INTERNATIONAL7SDL_SCANCODE_INTERNATIONAL7
sdl.keyboard.SCANCODE.INTERNATIONAL8SDL_SCANCODE_INTERNATIONAL8
sdl.keyboard.SCANCODE.INTERNATIONAL9SDL_SCANCODE_INTERNATIONAL9
sdl.keyboard.SCANCODE.LANG1SDL_SCANCODE_LANG1Hangul/English toggle
sdl.keyboard.SCANCODE.LANG2SDL_SCANCODE_LANG2Hanja conversion
sdl.keyboard.SCANCODE.LANG3SDL_SCANCODE_LANG3Katakana
sdl.keyboard.SCANCODE.LANG4SDL_SCANCODE_LANG4Hiragana
sdl.keyboard.SCANCODE.LANG5SDL_SCANCODE_LANG5Zenkaku/Hankaku
sdl.keyboard.SCANCODE.LANG6SDL_SCANCODE_LANG6
sdl.keyboard.SCANCODE.LANG7SDL_SCANCODE_LANG7
sdl.keyboard.SCANCODE.LANG8SDL_SCANCODE_LANG8
sdl.keyboard.SCANCODE.LANG9SDL_SCANCODE_LANG9
sdl.keyboard.SCANCODE.ALTERASESDL_SCANCODE_ALTERASEErase-Eaze
sdl.keyboard.SCANCODE.SYSREQSDL_SCANCODE_SYSREQ
sdl.keyboard.SCANCODE.CANCELSDL_SCANCODE_CANCEL
sdl.keyboard.SCANCODE.CLEARSDL_SCANCODE_CLEAR
sdl.keyboard.SCANCODE.PRIORSDL_SCANCODE_PRIOR
sdl.keyboard.SCANCODE.RETURN2SDL_SCANCODE_RETURN2
sdl.keyboard.SCANCODE.SEPARATORSDL_SCANCODE_SEPARATOR
sdl.keyboard.SCANCODE.OUTSDL_SCANCODE_OUT
sdl.keyboard.SCANCODE.OPERSDL_SCANCODE_OPER
sdl.keyboard.SCANCODE.CLEARAGAINSDL_SCANCODE_CLEARAGAIN
sdl.keyboard.SCANCODE.CRSELSDL_SCANCODE_CRSEL
sdl.keyboard.SCANCODE.EXSELSDL_SCANCODE_EXSEL
sdl.keyboard.SCANCODE.KP_00SDL_SCANCODE_KP_00
sdl.keyboard.SCANCODE.KP_000SDL_SCANCODE_KP_000
sdl.keyboard.SCANCODE.THOUSANDSSEPARATORSDL_SCANCODE_THOUSANDSSEPARATOR
sdl.keyboard.SCANCODE.DECIMALSEPARATORSDL_SCANCODE_DECIMALSEPARATOR
sdl.keyboard.SCANCODE.CURRENCYUNITSDL_SCANCODE_CURRENCYUNIT
sdl.keyboard.SCANCODE.CURRENCYSUBUNITSDL_SCANCODE_CURRENCYSUBUNIT
sdl.keyboard.SCANCODE.KP_LEFTPARENSDL_SCANCODE_KP_LEFTPAREN
sdl.keyboard.SCANCODE.KP_RIGHTPARENSDL_SCANCODE_KP_RIGHTPAREN
sdl.keyboard.SCANCODE.KP_LEFTBRACESDL_SCANCODE_KP_LEFTBRACE
sdl.keyboard.SCANCODE.KP_RIGHTBRACESDL_SCANCODE_KP_RIGHTBRACE
sdl.keyboard.SCANCODE.KP_TABSDL_SCANCODE_KP_TAB
sdl.keyboard.SCANCODE.KP_BACKSPACESDL_SCANCODE_KP_BACKSPACE
sdl.keyboard.SCANCODE.KP_ASDL_SCANCODE_KP_A
sdl.keyboard.SCANCODE.KP_BSDL_SCANCODE_KP_B
sdl.keyboard.SCANCODE.KP_CSDL_SCANCODE_KP_C
sdl.keyboard.SCANCODE.KP_DSDL_SCANCODE_KP_D
sdl.keyboard.SCANCODE.KP_ESDL_SCANCODE_KP_E
sdl.keyboard.SCANCODE.KP_FSDL_SCANCODE_KP_F
sdl.keyboard.SCANCODE.KP_XORSDL_SCANCODE_KP_XOR
sdl.keyboard.SCANCODE.KP_POWERSDL_SCANCODE_KP_POWER
sdl.keyboard.SCANCODE.KP_PERCENTSDL_SCANCODE_KP_PERCENT
sdl.keyboard.SCANCODE.KP_LESSSDL_SCANCODE_KP_LESS
sdl.keyboard.SCANCODE.KP_GREATERSDL_SCANCODE_KP_GREATER
sdl.keyboard.SCANCODE.KP_AMPERSANDSDL_SCANCODE_KP_AMPERSAND
sdl.keyboard.SCANCODE.KP_DBLAMPERSANDSDL_SCANCODE_KP_DBLAMPERSAND
sdl.keyboard.SCANCODE.KP_VERTICALBARSDL_SCANCODE_KP_VERTICALBAR
sdl.keyboard.SCANCODE.KP_DBLVERTICALBARSDL_SCANCODE_KP_DBLVERTICALBAR
sdl.keyboard.SCANCODE.KP_COLONSDL_SCANCODE_KP_COLON
sdl.keyboard.SCANCODE.KP_HASHSDL_SCANCODE_KP_HASH
sdl.keyboard.SCANCODE.KP_SPACESDL_SCANCODE_KP_SPACE
sdl.keyboard.SCANCODE.KP_ATSDL_SCANCODE_KP_AT
sdl.keyboard.SCANCODE.KP_EXCLAMSDL_SCANCODE_KP_EXCLAM
sdl.keyboard.SCANCODE.KP_MEMSTORESDL_SCANCODE_KP_MEMSTORE
sdl.keyboard.SCANCODE.KP_MEMRECALLSDL_SCANCODE_KP_MEMRECALL
sdl.keyboard.SCANCODE.KP_MEMCLEARSDL_SCANCODE_KP_MEMCLEAR
sdl.keyboard.SCANCODE.KP_MEMADDSDL_SCANCODE_KP_MEMADD
sdl.keyboard.SCANCODE.KP_MEMSUBTRACTSDL_SCANCODE_KP_MEMSUBTRACT
sdl.keyboard.SCANCODE.KP_MEMMULTIPLYSDL_SCANCODE_KP_MEMMULTIPLY
sdl.keyboard.SCANCODE.KP_MEMDIVIDESDL_SCANCODE_KP_MEMDIVIDE
sdl.keyboard.SCANCODE.KP_PLUSMINUSSDL_SCANCODE_KP_PLUSMINUS
sdl.keyboard.SCANCODE.KP_CLEARSDL_SCANCODE_KP_CLEAR
sdl.keyboard.SCANCODE.KP_CLEARENTRYSDL_SCANCODE_KP_CLEARENTRY
sdl.keyboard.SCANCODE.KP_BINARYSDL_SCANCODE_KP_BINARY
sdl.keyboard.SCANCODE.KP_OCTALSDL_SCANCODE_KP_OCTAL
sdl.keyboard.SCANCODE.KP_DECIMALSDL_SCANCODE_KP_DECIMAL
sdl.keyboard.SCANCODE.KP_HEXADECIMALSDL_SCANCODE_KP_HEXADECIMAL
sdl.keyboard.SCANCODE.LCTRLSDL_SCANCODE_LCTRL
sdl.keyboard.SCANCODE.LSHIFTSDL_SCANCODE_LSHIFT
sdl.keyboard.SCANCODE.LALTSDL_SCANCODE_LALTalt, option
sdl.keyboard.SCANCODE.LGUISDL_SCANCODE_LGUIwindows, command (apple), meta
sdl.keyboard.SCANCODE.RCTRLSDL_SCANCODE_RCTRL
sdl.keyboard.SCANCODE.RSHIFTSDL_SCANCODE_RSHIFT
sdl.keyboard.SCANCODE.RALTSDL_SCANCODE_RALTalt gr, option
sdl.keyboard.SCANCODE.RGUISDL_SCANCODE_RGUIwindows, command (apple), meta
sdl.keyboard.SCANCODE.MODESDL_SCANCODE_MODE
sdl.keyboard.SCANCODE.AUDIONEXTSDL_SCANCODE_AUDIONEXT
sdl.keyboard.SCANCODE.AUDIOPREVSDL_SCANCODE_AUDIOPREV
sdl.keyboard.SCANCODE.AUDIOSTOPSDL_SCANCODE_AUDIOSTOP
sdl.keyboard.SCANCODE.AUDIOPLAYSDL_SCANCODE_AUDIOPLAY
sdl.keyboard.SCANCODE.AUDIOMUTESDL_SCANCODE_AUDIOMUTE
sdl.keyboard.SCANCODE.MEDIASELECTSDL_SCANCODE_MEDIASELECT
sdl.keyboard.SCANCODE.WWWSDL_SCANCODE_WWW
sdl.keyboard.SCANCODE.MAILSDL_SCANCODE_MAIL
sdl.keyboard.SCANCODE.CALCULATORSDL_SCANCODE_CALCULATOR
sdl.keyboard.SCANCODE.COMPUTERSDL_SCANCODE_COMPUTER
sdl.keyboard.SCANCODE.AC_SEARCHSDL_SCANCODE_AC_SEARCH
sdl.keyboard.SCANCODE.AC_HOMESDL_SCANCODE_AC_HOME
sdl.keyboard.SCANCODE.AC_BACKSDL_SCANCODE_AC_BACK
sdl.keyboard.SCANCODE.AC_FORWARDSDL_SCANCODE_AC_FORWARD
sdl.keyboard.SCANCODE.AC_STOPSDL_SCANCODE_AC_STOP
sdl.keyboard.SCANCODE.AC_REFRESHSDL_SCANCODE_AC_REFRESH
sdl.keyboard.SCANCODE.AC_BOOKMARKSSDL_SCANCODE_AC_BOOKMARKS
sdl.keyboard.SCANCODE.BRIGHTNESSDOWNSDL_SCANCODE_BRIGHTNESSDOWN
sdl.keyboard.SCANCODE.BRIGHTNESSUPSDL_SCANCODE_BRIGHTNESSUP
sdl.keyboard.SCANCODE.DISPLAYSWITCHSDL_SCANCODE_DISPLAYSWITCHdisplay mirroring/dual display switch, video mode switch
sdl.keyboard.SCANCODE.KBDILLUMTOGGLESDL_SCANCODE_KBDILLUMTOGGLE
sdl.keyboard.SCANCODE.KBDILLUMDOWNSDL_SCANCODE_KBDILLUMDOWN
sdl.keyboard.SCANCODE.KBDILLUMUPSDL_SCANCODE_KBDILLUMUP
sdl.keyboard.SCANCODE.EJECTSDL_SCANCODE_EJECT
sdl.keyboard.SCANCODE.SLEEPSDL_SCANCODE_SLEEP
sdl.keyboard.SCANCODE.APP1SDL_SCANCODE_APP1
sdl.keyboard.SCANCODE.APP2SDL_SCANCODE_APP2
sdl.keyboard.SCANCODE.AUDIOREWINDSDL_SCANCODE_AUDIOREWIND
sdl.keyboard.SCANCODE.AUDIOFASTFORWARDSDL_SCANCODE_AUDIOFASTFORWARD

sdl.keyboard.getKey(scancode)

Maps a scancode to the corresponding key based on the current keyboard mapping. Retuns null if the scancode does not currespond to a key in the current mapping.

sdl.keyboard.getScancode(key)

Maps a key to the corresponding scancode based on the current keyboard mapping. Retuns null if the key does not currespond to a scancode in the current mapping. If multiple physical keys produce the same virtual key, then only the first one will be returned.

sdl.keyboard.getState()

  • Returns: <boolean[]> an object representing the state of each key.

The returned array can be indexed with Scancode values. The values will be true for keys that are pressed and false otherwise.

sdl.mouse

Enum: BUTTON

Used to represent the buttons on a mouse. A mouse can have many buttons, but the values for the three most common ones are represented in this enum.

ValueCorresponding SDL_BUTTON_*
sdl.mouse.BUTTON.LEFTSDL_BUTTON_LEFT
sdl.mouse.BUTTON.MIDDLESDL_BUTTON_MIDDLE
sdl.mouse.BUTTON.RIGHTSDL_BUTTON_RIGHT

sdl.mouse.getButton(button)

  • button: <number> The index of the button.
  • Returns: <boolean> Will be true if the button is pressed.

Queries the state of a single mouse button.

sdl.mouse.position

  • <object>
    • x: <number> The x position of the mouse, relative to the screen.
    • y: <number> The y position of the mouse, relative to the screen.

The position of the mouse on the screen.

sdl.mouse.setPosition(x, y)

  • x: <number> The new x position of the mouse, relative to the screen.
  • y: <number> The new y position of the mouse, relative to the screen.

Moves the mouse to the specified position.

sdl.mouse.setCursor(cursor)

  • cursor: <MouseCursor> The icon to use for the cursor.

Changes the icon that is displayed for the mouse cursor.

Possibl

0.10.7

1 day ago

0.10.6

4 days ago

0.10.4

2 months ago

0.10.3

2 months ago

0.10.2

2 months ago

0.10.1

3 months ago

0.10.0

3 months ago

0.9.6-1

4 months ago

0.9.6-0

4 months ago

0.9.5

5 months ago

0.9.4

5 months ago

0.9.3

5 months ago

0.8.4

8 months ago

0.9.0

6 months ago

0.9.2

5 months ago

0.9.1

6 months ago

0.7.6

10 months ago

0.7.8

10 months ago

0.7.7

10 months ago

0.8.0

8 months ago

0.8.3

8 months ago

0.7.5

11 months ago

0.7.2

12 months ago

0.7.4

12 months ago

0.7.3

12 months ago

0.6.9

1 year ago

0.7.1

1 year ago

0.7.0

1 year ago

0.6.7

1 year ago

0.6.6

1 year ago

0.6.8

1 year ago

0.6.3

1 year ago

0.6.2

1 year ago

0.6.5

1 year ago

0.6.4

1 year ago

0.6.1

1 year ago

0.6.0

1 year ago

0.4.5

2 years ago

0.4.4

2 years ago

0.5.0

2 years ago

0.4.1

2 years ago

0.4.0

2 years ago

0.5.2

2 years ago

0.4.3

2 years ago

0.4.2

2 years ago

0.3.7

2 years ago

0.3.6

2 years ago

0.3.5

2 years ago

0.3.4

3 years ago

0.3.3

3 years ago

0.3.2

3 years ago

0.3.1

3 years ago

0.2.1

3 years ago

0.2.0

3 years ago

0.1.1

3 years ago

0.2.3

3 years ago

0.2.2

3 years ago

0.0.19-alpha.0

3 years ago

0.0.11

3 years ago

0.0.12

3 years ago

0.0.13

3 years ago

0.0.14

3 years ago

0.1.0

3 years ago

0.0.15

3 years ago

0.0.16

3 years ago

0.0.18

3 years ago

0.0.10

3 years ago

0.0.9

3 years ago