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.traits; 17 import godot.core; 18 import godot.c; 19 import godot.d.bind; 20 import godot.d.reference; 21 import godot.globalenums; 22 import godot.object; 23 import godot.classdb; 24 import godot.inputeventwithmodifiers; 25 /** 26 Input event type for keyboard events. 27 28 Stores key presses on the keyboard. Supports key presses, key releases and $(D echo) events. 29 */ 30 @GodotBaseClass struct InputEventKey 31 { 32 package(godot) enum string _GODOT_internal_name = "InputEventKey"; 33 public: 34 @nogc nothrow: 35 union { /** */ godot_object _godot_object; /** */ InputEventWithModifiers _GODOT_base; } 36 alias _GODOT_base this; 37 alias BaseClasses = AliasSeq!(typeof(_GODOT_base), typeof(_GODOT_base).BaseClasses); 38 package(godot) __gshared bool _classBindingInitialized = false; 39 package(godot) static struct GDNativeClassBinding 40 { 41 __gshared: 42 @GodotName("get_scancode") GodotMethod!(long) getScancode; 43 @GodotName("get_scancode_with_modifiers") GodotMethod!(long) getScancodeWithModifiers; 44 @GodotName("get_unicode") GodotMethod!(long) getUnicode; 45 @GodotName("set_echo") GodotMethod!(void, bool) setEcho; 46 @GodotName("set_pressed") GodotMethod!(void, bool) setPressed; 47 @GodotName("set_scancode") GodotMethod!(void, long) setScancode; 48 @GodotName("set_unicode") GodotMethod!(void, long) setUnicode; 49 } 50 /// 51 pragma(inline, true) bool opEquals(in InputEventKey other) const 52 { return _godot_object.ptr is other._godot_object.ptr; } 53 /// 54 pragma(inline, true) typeof(null) opAssign(typeof(null) n) 55 { _godot_object.ptr = n; return null; } 56 /// 57 pragma(inline, true) bool opEquals(typeof(null) n) const 58 { return _godot_object.ptr is n; } 59 /// 60 size_t toHash() const @trusted { return cast(size_t)_godot_object.ptr; } 61 mixin baseCasts; 62 /// Construct a new instance of InputEventKey. 63 /// Note: use `memnew!InputEventKey` instead. 64 static InputEventKey _new() 65 { 66 static godot_class_constructor constructor; 67 if(constructor is null) constructor = _godot_api.godot_get_class_constructor("InputEventKey"); 68 if(constructor is null) return typeof(this).init; 69 return cast(InputEventKey)(constructor()); 70 } 71 @disable new(size_t s); 72 /** 73 74 */ 75 long getScancode() const 76 { 77 checkClassBinding!(typeof(this))(); 78 return ptrcall!(long)(GDNativeClassBinding.getScancode, _godot_object); 79 } 80 /** 81 Returns the scancode combined with modifier keys such as `Shift` or `Alt`. See also $(D InputEventWithModifiers). 82 To get a human-readable representation of the $(D InputEventKey) with modifiers, use `OS.get_scancode_string(event.get_scancode_with_modifiers())` where `event` is the $(D InputEventKey). 83 */ 84 long getScancodeWithModifiers() const 85 { 86 checkClassBinding!(typeof(this))(); 87 return ptrcall!(long)(GDNativeClassBinding.getScancodeWithModifiers, _godot_object); 88 } 89 /** 90 91 */ 92 long getUnicode() const 93 { 94 checkClassBinding!(typeof(this))(); 95 return ptrcall!(long)(GDNativeClassBinding.getUnicode, _godot_object); 96 } 97 /** 98 99 */ 100 void setEcho(in bool echo) 101 { 102 checkClassBinding!(typeof(this))(); 103 ptrcall!(void)(GDNativeClassBinding.setEcho, _godot_object, echo); 104 } 105 /** 106 107 */ 108 void setPressed(in bool pressed) 109 { 110 checkClassBinding!(typeof(this))(); 111 ptrcall!(void)(GDNativeClassBinding.setPressed, _godot_object, pressed); 112 } 113 /** 114 115 */ 116 void setScancode(in long scancode) 117 { 118 checkClassBinding!(typeof(this))(); 119 ptrcall!(void)(GDNativeClassBinding.setScancode, _godot_object, scancode); 120 } 121 /** 122 123 */ 124 void setUnicode(in long unicode) 125 { 126 checkClassBinding!(typeof(this))(); 127 ptrcall!(void)(GDNativeClassBinding.setUnicode, _godot_object, unicode); 128 } 129 /** 130 If `true`, the key was already pressed before this event. It means the user is holding the key down. 131 */ 132 @property bool echo() 133 { 134 return isEcho(); 135 } 136 /// ditto 137 @property void echo(bool v) 138 { 139 setEcho(v); 140 } 141 /** 142 If `true`, the key's state is pressed. If `false`, the key's state is released. 143 */ 144 @property bool pressed() 145 { 146 return isPressed(); 147 } 148 /// ditto 149 @property void pressed(bool v) 150 { 151 setPressed(v); 152 } 153 /** 154 The key scancode, which corresponds to one of the $(D keylist) constants. 155 To get a human-readable representation of the $(D InputEventKey), use `OS.get_scancode_string(event.scancode)` where `event` is the $(D InputEventKey). 156 */ 157 @property long scancode() 158 { 159 return getScancode(); 160 } 161 /// ditto 162 @property void scancode(long v) 163 { 164 setScancode(v); 165 } 166 /** 167 The key Unicode identifier (when relevant). Unicode identifiers for the composite characters and complex scripts may not be available unless IME input mode is active. See $(D OS.setImeActive) for more information. 168 */ 169 @property long unicode() 170 { 171 return getUnicode(); 172 } 173 /// ditto 174 @property void unicode(long v) 175 { 176 setUnicode(v); 177 } 178 }