sfml3.rb

Module: SFML::Keyboard

Defined in:
ext/window/keyboard.c,
ext/window/keyboard.c

Overview

Real-time keyboard state and key/scancode lookups.

Class Method Summary collapse

Class Method Details

.delocalize(key) ⇒ Integer

Returns the scancode that produces key on the current keyboard layout.

Returns:

  • (Integer)

Returns:

  • (Integer) —

    the scancode that produces key on the current keyboard layout

Raises:

  • (ArgumentError) —

    if key is a Symbol/String naming an unknown key



217
218
219
# File 'ext/window/keyboard.c', line 217

static VALUE Keyboard_delocalize(VALUE module, VALUE rb_key) {
    return INT2NUM(sfKeyboard_delocalize((sfKeyCode)Keyboard_key_code(rb_key)));
}

.description(scancode) ⇒ String

Returns a human-readable, localized name for scancode.

Returns:

  • (String)

Returns:

  • (String) —

    a human-readable, localized name for scancode



228
229
230
231
232
# File 'ext/window/keyboard.c', line 228

static VALUE Keyboard_description(VALUE module, VALUE rb_scancode) {
    const char* description = sfKeyboard_getDescription((sfScancode)NUM2INT(rb_scancode));

    return rb_str_new_cstr(description != NULL ? description : "");
}

.localize(scancode) ⇒ Symbol

Returns the key Symbol that scancode produces on the current layout.

Returns:

  • (Symbol)

Returns:

  • (Symbol) —

    the key that scancode produces on the current keyboard layout



203
204
205
206
# File 'ext/window/keyboard.c', line 203

static VALUE Keyboard_localize(VALUE module, VALUE rb_scancode) {
    return ID2SYM(rb_intern(
        get_key_event((unsigned int)sfKeyboard_localize((sfScancode)NUM2INT(rb_scancode)))));
}

.pressed?(key) ⇒ Boolean

key may be a key Symbol (e.g. :a, :Enter, :LShift), a String key name, or an Integer key code.

Returns:

  • (Boolean)

Returns:

  • (Boolean)

Raises:

  • (ArgumentError) —

    if key is a Symbol/String naming an unknown key



179
180
181
# File 'ext/window/keyboard.c', line 179

static VALUE Keyboard_pressed_p(VALUE module, VALUE rb_key) {
    return BOOL2RB(sfKeyboard_isKeyPressed((sfKeyCode)Keyboard_key_code(rb_key)));
}

.scancode_pressed?(scancode) ⇒ Boolean

Unlike #pressed?, scancode identifies a physical key position rather than the character it currently produces.

Returns:

  • (Boolean)

Returns:

  • (Boolean)


191
192
193
# File 'ext/window/keyboard.c', line 191

static VALUE Keyboard_scancode_pressed_p(VALUE module, VALUE rb_scancode) {
    return BOOL2RB(sfKeyboard_isScancodePressed((sfScancode)NUM2INT(rb_scancode)));
}

.virtual_keyboard_visible=(value) ⇒ Boolean

Shows or hides the on-screen keyboard, where the platform provides one.

Returns:

  • (Boolean)

Returns:

  • (Boolean) —

    value



241
242
243
244
# File 'ext/window/keyboard.c', line 241

static VALUE Keyboard_set_virtual_keyboard_visible(VALUE module, VALUE rb_visible) {
    sfKeyboard_setVirtualKeyboardVisible(RTEST(rb_visible));
    return rb_visible;
}