1 /** 2 Input event type for keyboard events. 3 4 Copyright: 5 Copyright (c) 2007-2018 Juan Linietsky, Ariel Manzur. 6 Copyright (c) 2014-2018 Godot Engine contributors (cf. AUTHORS.md) 7 Copyright (c) 2017-2018 Godot-D contributors 8 9 License: $(LINK2 https://opensource.org/licenses/MIT, MIT License) 10 11 12 */ 13 module godot.inputeventkey; 14 import std.meta : AliasSeq, staticIndexOf; 15 import std.traits : Unqual; 16 import godot.d.meta; 17 import godot.core; 18 import godot.c; 19 import godot.d.bind; 20 import godot.d.reference; 21 import godot.object; 22 import godot.classdb; 23 import godot.inputeventwithmodifiers; 24 import godot.inputevent; 25 import godot.resource; 26 import godot.reference; 27 /** 28 Input event type for keyboard events. 29 30 Stores key presses on the keyboard. Supports key presses, key releases and $(D echo) events. 31 */ 32 @GodotBaseClass struct InputEventKey 33 { 34 enum string _GODOT_internal_name = "InputEventKey"; 35 public: 36 @nogc nothrow: 37 union { godot_object _godot_object; InputEventWithModifiers _GODOT_base; } 38 alias _GODOT_base this; 39 alias BaseClasses = AliasSeq!(typeof(_GODOT_base), typeof(_GODOT_base).BaseClasses); 40 package(godot) __gshared bool _classBindingInitialized = false; 41 package(godot) static struct _classBinding 42 { 43 __gshared: 44 @GodotName("set_pressed") GodotMethod!(void, bool) setPressed; 45 @GodotName("set_scancode") GodotMethod!(void, long) setScancode; 46 @GodotName("get_scancode") GodotMethod!(long) getScancode; 47 @GodotName("set_unicode") GodotMethod!(void, long) setUnicode; 48 @GodotName("get_unicode") GodotMethod!(long) getUnicode; 49 @GodotName("set_echo") GodotMethod!(void, bool) setEcho; 50 @GodotName("get_scancode_with_modifiers") GodotMethod!(long) getScancodeWithModifiers; 51 } 52 bool opEquals(in InputEventKey other) const { return _godot_object.ptr is other._godot_object.ptr; } 53 InputEventKey opAssign(T : typeof(null))(T n) { _godot_object.ptr = null; } 54 bool opEquals(typeof(null) n) const { return _godot_object.ptr is null; } 55 mixin baseCasts; 56 static InputEventKey _new() 57 { 58 static godot_class_constructor constructor; 59 if(constructor is null) constructor = _godot_api.godot_get_class_constructor("InputEventKey"); 60 if(constructor is null) return typeof(this).init; 61 return cast(InputEventKey)(constructor()); 62 } 63 @disable new(size_t s); 64 /** 65 66 */ 67 void setPressed(in bool pressed) 68 { 69 checkClassBinding!(typeof(this))(); 70 ptrcall!(void)(_classBinding.setPressed, _godot_object, pressed); 71 } 72 /** 73 74 */ 75 void setScancode(in long scancode) 76 { 77 checkClassBinding!(typeof(this))(); 78 ptrcall!(void)(_classBinding.setScancode, _godot_object, scancode); 79 } 80 /** 81 82 */ 83 long getScancode() const 84 { 85 checkClassBinding!(typeof(this))(); 86 return ptrcall!(long)(_classBinding.getScancode, _godot_object); 87 } 88 /** 89 90 */ 91 void setUnicode(in long unicode) 92 { 93 checkClassBinding!(typeof(this))(); 94 ptrcall!(void)(_classBinding.setUnicode, _godot_object, unicode); 95 } 96 /** 97 98 */ 99 long getUnicode() const 100 { 101 checkClassBinding!(typeof(this))(); 102 return ptrcall!(long)(_classBinding.getUnicode, _godot_object); 103 } 104 /** 105 106 */ 107 void setEcho(in bool echo) 108 { 109 checkClassBinding!(typeof(this))(); 110 ptrcall!(void)(_classBinding.setEcho, _godot_object, echo); 111 } 112 /** 113 Returns the scancode combined with modifier keys such as `Shift` or `Alt`. See also $(D InputEventWithModifiers). 114 */ 115 long getScancodeWithModifiers() const 116 { 117 checkClassBinding!(typeof(this))(); 118 return ptrcall!(long)(_classBinding.getScancodeWithModifiers, _godot_object); 119 } 120 /** 121 If `true` the key's state is pressed. If `false` the key's state is released. 122 */ 123 @property bool pressed() 124 { 125 return isPressed(); 126 } 127 /// ditto 128 @property void pressed(bool v) 129 { 130 setPressed(v); 131 } 132 /** 133 Key scancode, one of the `KEY_*` constants in $(D @GlobalScope). 134 */ 135 @property long scancode() 136 { 137 return getScancode(); 138 } 139 /// ditto 140 @property void scancode(long v) 141 { 142 setScancode(v); 143 } 144 /** 145 Key unicode identifier when relevant. 146 */ 147 @property long unicode() 148 { 149 return getUnicode(); 150 } 151 /// ditto 152 @property void unicode(long v) 153 { 154 setUnicode(v); 155 } 156 /** 157 If `true` the key was already pressed before this event. It means the user is holding the key down. 158 */ 159 @property bool echo() 160 { 161 return isEcho(); 162 } 163 /// ditto 164 @property void echo(bool v) 165 { 166 setEcho(v); 167 } 168 }