Skip to content

Commit

Permalink
Added: Added action and flags to KeyEvent.
Browse files Browse the repository at this point in the history
  • Loading branch information
tareksander committed Feb 15, 2024
1 parent 5ecf04e commit b8bedec
Show file tree
Hide file tree
Showing 2 changed files with 100 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import android.text.TextWatcher
import android.util.DisplayMetrics
import android.util.Log
import android.util.TypedValue
import android.view.KeyEvent
import android.view.MotionEvent
import android.view.View
import android.view.View.OnKeyListener
Expand Down Expand Up @@ -218,6 +219,11 @@ class ProtoUtils {
fun keyListener(eventQueue: LinkedBlockingQueue<GUIProt0.Event>, v: GUIProt0.View): OnKeyListener {
return OnKeyListener { _, _, event ->
val b = GUIProt0.KeyEvent.newBuilder()
b.flags = event.flags
when (event.action) {
KeyEvent.ACTION_DOWN -> b.action = GUIProt0.KeyAction.ACTION_DOWN
KeyEvent.ACTION_UP -> b.action = GUIProt0.KeyAction.ACTION_UP
}
b.v = v
b.codePoint = event.unicodeChar
var mod = 0
Expand Down
95 changes: 94 additions & 1 deletion app/src/main/proto/GUIProt0.proto
Original file line number Diff line number Diff line change
Expand Up @@ -3074,9 +3074,11 @@ message KeyEvent {
MOD_NUM_LOCK = 256;
}
View v = 1;
uint32 code = 2; // The Android keycode, refer to https://developer.android.com/reference/android/view/KeyEvent for the values.
uint32 code = 2; // The Android keycode, refer to https://developer.android.com/reference/android/view/KeyEvent for the values. Values are provided in the KeyCode enum.
uint32 modifiers = 3; // Bits are according to the Modifier enum.
uint32 codePoint = 4; // The unicode code point of the character.
KeyAction action = 5; // The Action, that is if the key was pressed or released.
uint32 flags = 6; // The flags of the key event.
}


Expand Down Expand Up @@ -3216,6 +3218,97 @@ message Event {
}


enum KeyAction {
/**
* {@link #getAction} value: the key has been pressed down.
*/
ACTION_DOWN = 0;
/**
* {@link #getAction} value: the key has been released.
*/
ACTION_UP = 1;
}


enum KeyFlag {
FLAG_NONE = 0;

/**
* This mask is set if the key event was generated by a software keyboard.
*/
FLAG_SOFT_KEYBOARD = 0x2;

/**
* This mask is set if we don't want the key event to cause us to leave
* touch mode.
*/
FLAG_KEEP_TOUCH_MODE = 0x4;

/**
* This mask is set if an event was known to come from a trusted part
* of the system. That is, the event is known to come from the user,
* and could not have been spoofed by a third party component.
*/
FLAG_FROM_SYSTEM = 0x8;

/**
* This mask is used for compatibility, to identify enter keys that are
* coming from an IME whose enter key has been auto-labelled "next" or
* "done". This allows TextView to dispatch these as normal enter keys
* for old applications, but still do the appropriate action when
* receiving them.
*/
FLAG_EDITOR_ACTION = 0x10;

/**
* When associated with up key events, this indicates that the key press
* has been canceled. Typically this is used with virtual touch screen
* keys, where the user can slide from the virtual key area on to the
* display: in that case, the application will receive a canceled up
* event and should not perform the action normally associated with the
* key. Note that for this to work, the application can not perform an
* action for a key until it receives an up or the long press timeout has
* expired.
*/
FLAG_CANCELED = 0x20;

/**
* This key event was generated by a virtual (on-screen) hard key area.
* Typically this is an area of the touchscreen, outside of the regular
* display, dedicated to "hardware" buttons.
*/
FLAG_VIRTUAL_HARD_KEY = 0x40;

/**
* This flag is set for the first key repeat that occurs after the
* long press timeout.
*/
FLAG_LONG_PRESS = 0x80;

/**
* Set when a key event has {@link #FLAG_CANCELED} set because a long
* press action was executed while it was down.
*/
FLAG_CANCELED_LONG_PRESS = 0x100;

/**
* Set for {@link #ACTION_UP} when this event's key code is still being
* tracked from its initial down. That is, somebody requested that tracking
* started on the key down and a long press has not caused
* the tracking to be canceled.
*/
FLAG_TRACKING = 0x200;

/**
* Set when a key event has been synthesized to implement default behavior
* for an event that the application did not handle.
* Fallback key events are generated by unhandled trackball motions
* (to emulate a directional keypad) and by certain unhandled key presses
* that are declared in the key map (such as special function numeric keypad
* keys when numlock is off).
*/
FLAG_FALLBACK = 0x400;
}

// Auto-generated from Android SDK sources, DO NOT TOUCH
/// For documentation, see https://developer.android.com/reference/android/view/KeyEvent#KEYCODE_0
Expand Down

0 comments on commit b8bedec

Please sign in to comment.