indexing description: "[ Keyboard event ]" date: "$Date$" revision: "$Revision$" class EM_KEYBOARD_EVENT inherit EM_EVENT redefine out, make, type end SDLKEY_ENUM_EXTERNAL rename is_valid_enum as is_valid_key undefine out end SDLMOD_ENUM_EXTERNAL rename is_valid_enum as is_valid_keyboard_modifier_flag undefine out end SDL_KEYBOARD_FUNCTIONS export {NONE} all undefine out end create make feature {NONE} -- Initialization make (a_pointer: POINTER) is -- Create a keyboard event. do Precursor (a_pointer) create sdl_keyboard_event_struct.make_shared (a_pointer) create sdl_keyboard_symbol_struct.make_shared (sdl_keyboard_event_struct.keysym) end feature -- Access type: INTEGER is -- Event type value -- (`em_key_down_event' or `em_key_up_event') do Result := sdl_keyboard_event_struct.type end key: INTEGER is -- Key value -- (See sdlk_... features in SDLKEY_ENUM_EXTERNAL for possible values) do Result := sdl_keyboard_symbol_struct.sym end character: CHARACTER is -- Character representing the key of the current event, -- not a meaningfull value for all keys, -- better use `unicode_character' for reliable characters -- (i.e. for textual input) do Result := sdl_keyboard_symbol_struct.sym.to_character end unicode_character: CHARACTER is -- Character entered in the current key down event (not valid for key up events) -- only meaningful if `is_unicode_characters_enabled' in EM_KEYBOARD. do Result := sdl_keyboard_symbol_struct.unicode.to_character end key_name: STRING is -- SDL-Name for key local str: EWG_ZERO_TERMINATED_STRING p: POINTER do p := sdl_get_key_name (key) if p /= Default_pointer then create str.make_shared (p) Result := str.string end end keyboard_modifiers: INTEGER is -- Keyboard modifier flags specifying which keyboard modifiers are currently on -- (see kmod_... features in SDLMOD_ENUM_EXTERNAL for possible flags) do Result := sdl_keyboard_symbol_struct.mod end feature -- Status report is_key_up: BOOLEAN is -- Is it a key up event? do Result := (type = em_key_up_event) end is_key_down: BOOLEAN is -- Is it a key down event? do Result := (type = em_key_down_event) end is_keyboard_modifier_on (keyboard_modifier_flag: INTEGER): BOOLEAN is -- Is `keyboard modifier_flag' turned on in `keyboard_modifier_flags'. -- (see kmod_... features in SDLMOD_ENUM_EXTERNAL for possible `keyboard_modifier_flag' values) require valid_keyboard_modifier_flag: is_valid_keyboard_modifier_flag (keyboard_modifier_flag) do Result := keyboard_modifiers & keyboard_modifier_flag = keyboard_modifier_flag end is_shift_pressed: BOOLEAN is -- Is a shift key currently pressed? do Result := is_shift_left_pressed or else is_shift_right_pressed end is_shift_left_pressed: BOOLEAN is -- Is left shift key currently pressed? do Result := is_keyboard_modifier_on (kmod_lshift) end is_shift_right_pressed: BOOLEAN is -- Is right shift key currently pressed? do Result := is_keyboard_modifier_on (kmod_rshift) end is_control_pressed: BOOLEAN is -- Is a control key currently pressed? do Result := is_control_left_pressed or else is_control_right_pressed end is_control_left_pressed: BOOLEAN is -- Is left control key currently pressed? do Result := is_keyboard_modifier_on (kmod_lctrl) end is_control_right_pressed: BOOLEAN is -- Is right control key currently pressed? do Result := is_keyboard_modifier_on (kmod_rctrl) end is_alt_pressed: BOOLEAN is -- Is an alt key currently pressed? do Result := is_alt_left_pressed or else is_alt_right_pressed end is_alt_left_pressed: BOOLEAN is -- Is left alt key currently pressed? do Result := is_keyboard_modifier_on (kmod_lalt) end is_alt_right_pressed: BOOLEAN is -- Is right alt key currently pressed? do Result := is_keyboard_modifier_on (kmod_ralt) end is_num_locked: BOOLEAN is -- Is num lock enabled? do Result := is_keyboard_modifier_on (kmod_num) end is_caps_locked: BOOLEAN is -- Is caps lock enabled? do Result := is_keyboard_modifier_on (kmod_caps) end feature -- Output out: STRING is -- Textual representation do Result := "EM_KEYBOARD_EVENT " if is_key_down then Result := Result + " down: " end if is_key_up then Result := Result + " up: " end if is_control_left_pressed then Result := Result + "[CONTROL_LEFT] + " end if is_control_right_pressed then Result := Result + "[CONTROL_RIGHT] + " end if is_alt_left_pressed then Result := Result + "[ALT_LEFT] + " end if is_alt_right_pressed then Result := Result + "[ALT_RIGHT] + " end if is_shift_left_pressed then Result := Result + "[SHIFT_LEFT] + " end if is_shift_right_pressed then Result := Result + "[SHIFT_RIGHT] + " end Result := Result + key_name if is_caps_locked then Result := Result + " (CAPS_LOCK) " end if is_num_locked then Result := Result + " (NUM_LOCK) " end end feature {NONE} -- Implementation sdl_keyboard_event_struct: SDL_KEYBOARD_EVENT_STRUCT -- Wrapped struct containing informatiuon about the keyboard event. sdl_keyboard_symbol_struct: SDL_KEYSYM_STRUCT -- Wrapped struct containing information about the key. invariant sdl_keyboard_event_struct_not_void: sdl_keyboard_event_struct /= Void sdl_keyboard_symbol_struct_not_void: sdl_keyboard_symbol_struct /= Void end