Best code examples for Android KeyEvent class (android.view.KeyEvent)

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Android KeyEvent class.
You can now enable Codota on your own code to easily search and navigate your Java codebase.

Android KeyEvent examples from Open Source projects
Examples using Android KeyEvent getAction method:
This code example shows how to use the following methods: getAction, getRepeatCount, isCanceled
94:	if (event.getAction() == KeyEvent.ACTION_DOWN 
95:	&& event.getRepeatCount() == 0) { 
-
107:	} else if (event.getAction() == KeyEvent.ACTION_UP && !event.isCanceled()) { 
-
124:	return mMenu.performShortcut(keyCode, event, 0); 
Full Snippet Info
9
CodeRank
This code example shows how to use the following methods: getAction, getKeyCode, isCanceled, isTracking, handleKeyUp
64:	final int action = event.getAction(); 
65:	final int keyCode = event.getKeyCode(); 
-
198:	if (!event.isCanceled()) { 
-
202:	getAudioManager().handleKeyUp(event, AudioManager.USE_DEFAULT_STREAM_TYPE); 
-
227:	if (event.isTracking() && !event.isCanceled()) { 
-
237:	if (event.isTracking() && !event.isCanceled()) { 
Full Snippet Info
8
CodeRank
This code example shows how to use the following methods: getAction, getRepeatCount, isCanceled
94:	if (event.getAction() == KeyEvent.ACTION_DOWN 
95:	&& event.getRepeatCount() == 0) { 
-
107:	} else if (event.getAction() == KeyEvent.ACTION_UP && !event.isCanceled()) { 
-
124:	return mMenu.performShortcut(keyCode, event, 0); 
Full Snippet Info
8
CodeRank
Examples using Android KeyEvent getKeyCode method:
This code example shows how to use the following methods: getAction, getKeyCode
78:	boolean down = event.getAction() == KeyEvent.ACTION_DOWN; 
79:	switch (event.getKeyCode()) { 
Full Snippet Info
7
CodeRank
This code example shows how to use the following methods: getAction, getKeyCode
216:	int action = event.getAction(); 
217:	int keyCode = event.getKeyCode(); 
-
224:	if ( readingFragment.dispatchKeyEvent(event) ) { 
-
228:	return super.dispatchKeyEvent(event); 
Full Snippet Info
7
CodeRank
This code example shows how to use the following methods: getAction, getKeyCode, getMetaState, getUnicodeChar
85:	switch (event.getAction()) { 
-
87:	int uni = event.getUnicodeChar(event.getMetaState()); 
88:	return handleKeyDown(event.getKeyCode(), uni); 
-
90:	return handleKeyUp(event.getKeyCode()); 
Full Snippet Info
7
CodeRank
Examples using Android KeyEvent getRepeatCount method:
This code example shows how to use the following methods: getAction, getKeyCode, getRepeatCount, isCanceled
25:	if (parent_ != null && event.getKeyCode() == KeyEvent.KEYCODE_BACK) { 
-
28:	if (event.getAction() == KeyEvent.ACTION_DOWN && 
29:	event.getRepeatCount() == 0) { 
-
32:	} else if (event.getAction() == KeyEvent.ACTION_UP && 
33:	!event.isCanceled() && state.isTracking(event)) { 
Full Snippet Info
7
CodeRank
This code example shows how to use the following methods: getAction, getRepeatCount, isCanceled
57:	if (event.getAction() == KeyEvent.ACTION_DOWN 
58:	&& event.getRepeatCount() == 0) { 
-
71:	} else if (event.getAction() == KeyEvent.ACTION_UP 
72:	&& !event.isCanceled()) { 
-
88:	return mMenu.performShortcut(keyCode, event, 0); 
Full Snippet Info
7
CodeRank
This code example shows how to use the following methods: getAction, getRepeatCount
47:	if (event.getAction() == KeyEvent.ACTION_DOWN && 
48:	event.getRepeatCount() == 0 && action(CLICK, widget, buffer)) { 
Full Snippet Info
7
CodeRank
Examples using Android KeyEvent getEventTime method:
This code example shows how to use the following methods: getAction, getEventTime, getKeyCode, getMetaState, getUnicodeChar
383:	int action = event.getAction(); 
-
399:	return nativeSendKeyEvent(mNativeImeAdapterAndroid, event, event.getAction(), 
400:	getModifiers(event.getMetaState()), event.getEventTime(), event.getKeyCode(), 
401:	event.isSystem(), event.getUnicodeChar()); 
Full Snippet Info
7
CodeRank
Examples using Android KeyEvent isCanceled method:
This code example shows how to use the following methods: getAction, getKeyCode, isCanceled, isTracking, handleKeyUp
64:	final int action = event.getAction(); 
65:	final int keyCode = event.getKeyCode(); 
-
197:	if (!event.isCanceled()) { 
-
201:	getAudioManager().handleKeyUp(event, AudioManager.USE_DEFAULT_STREAM_TYPE); 
-
226:	if (event.isTracking() && !event.isCanceled()) { 
-
236:	if (event.isTracking() && !event.isCanceled()) { 
Full Snippet Info
8
CodeRank
This code example shows how to use the following methods: getAction, getKeyCode, getRepeatCount, isCanceled
69:	if (activity != null && event.getKeyCode() == KeyEvent.KEYCODE_BACK) { 
-
72:	if (event.getAction() == KeyEvent.ACTION_DOWN 
73:	&& event.getRepeatCount() == 0) { 
-
76:	} else if (event.getAction() == KeyEvent.ACTION_UP 
77:	&& !event.isCanceled() && state.isTracking(event)) { 
Full Snippet Info
7
CodeRank
This code example shows how to use the following methods: getAction, getKeyCode, getRepeatCount, isCanceled
32:	if (activity != null && event.getKeyCode() == KeyEvent.KEYCODE_BACK) { 
-
35:	if (event.getAction() == KeyEvent.ACTION_DOWN && event.getRepeatCount() == 0) { 
-
38:	} else if (event.getAction() == KeyEvent.ACTION_UP && !event.isCanceled() && state.isTracking(event)) { 
Full Snippet Info
6
CodeRank
Examples using Android KeyEvent getUnicodeChar method:
This code example shows how to use the following methods: getAction, getKeyCode, getUnicodeChar
318:	if (event.getAction() == KeyEvent.ACTION_UP) { 
319:	if (event.getKeyCode() == KeyEvent.KEYCODE_DEL) { 
-
321:	} else if (event.getKeyCode() == KeyEvent.KEYCODE_FORWARD_DEL) { 
-
324:	int unicodeChar = event.getUnicodeChar(); 
-
338:	} else if (event.getAction() == KeyEvent.ACTION_DOWN) { 
-
340:	if (event.getKeyCode() == KeyEvent.KEYCODE_ENTER) { 
-
343:	mImeAdapter.translateAndSendNativeEvents(event); 
-
348:	mImeAdapter.translateAndSendNativeEvents(event); 
Full Snippet Info
7
CodeRank
This code example shows how to use the following methods: getAction, getKeyCode, getUnicodeChar
244:	ret = keyEvent(event.getAction(), event.getUnicodeChar(), event.getKeyCode(), event); 
Full Snippet Info
6
CodeRank
Examples using Android KeyEvent getDownTime method:
This code example shows how to use the following methods: getAction, getDownTime, getEventTime, getKeyCode
41:	if(evt.getAction() == KeyEvent.ACTION_DOWN) { 
-
44:	Log.d(TAG, "TIME %d %d", evt.getDownTime(), evt.getEventTime()); 
-
52:	} else if(evt.getAction() == KeyEvent.ACTION_UP) { 
-
54:	int keycode = evt.getKeyCode(); 
-
56:	int pressTime = (int)(evt.getEventTime() - evt.getDownTime()); 
Full Snippet Info
7
CodeRank
Examples using Android KeyEvent getDeviceId method:
This code example shows how to use the following methods: getDeviceId, getKeyCode, getRepeatCount, getScanCode, sleep
192:	if (evt.getKeyCode() == KeyEvent.KEYCODE_SHIFT_LEFT || evt.getKeyCode() == KeyEvent.KEYCODE_SHIFT_RIGHT) 
-
196:	lowerCaseEvt.getKeyCode(), evt.getRepeatCount(), androidMeta, evt.getDeviceId(), evt.getScanCode()); 
-
199:	try { Thread.sleep(20); } catch (InterruptedException e) { } 
-
201:	lowerCaseEvt.getKeyCode(), evt.getRepeatCount(), 0, evt.getDeviceId(), evt.getScanCode()); 
Full Snippet Info
6
CodeRank
This code example shows how to use the following methods: getAction, getDeviceId
24:	if( KeyEvent.ACTION_DOWN == keyEvent.getAction() ) 
-
28:	OuyaController.onKeyDown( keyCode, keyEvent ); 
-
30:	controller = OuyaController.getControllerByDeviceId( keyEvent.getDeviceId() ); 
-
38:	OuyaController.onKeyUp( keyCode, keyEvent ); 
-
40:	controller = OuyaController.getControllerByDeviceId( keyEvent.getDeviceId() ); 
Full Snippet Info
6
CodeRank
Examples using Android KeyEvent getMetaState method:
This code example shows how to use the following methods: getMetaState, getUnicodeChar, handleKeyDown
312:	mMetaState = MetaKeyKeyListener.handleKeyDown(mMetaState, 
-
314:	int c = event.getUnicodeChar(MetaKeyKeyListener.getMetaState(mMetaState)); 
-
382:	&& (event.getMetaState()&KeyEvent.META_ALT_ON) != 0) { 
Full Snippet Info
6
CodeRank
Examples using Android KeyEvent isSystem method:
This code example shows how to use the following methods: getAction, getRepeatCount, isSystem
259:	if (!event.isSystem() && 
-
267:	switch (event.getAction()) { 
-
269:	return mLauncher.onKeyDown(keyCode, event); 
-
271:	return mLauncher.onKeyMultiple(keyCode, event.getRepeatCount(), event); 
-
273:	return mLauncher.onKeyUp(keyCode, event); 
Full Snippet Info
6
CodeRank
Examples for other Android KeyEvent methods:
Related Android KeyEvent Questions & Answers:
Other Android KeyEvent Examples
27:		
28:		@Override
29:		public boolean onKeyDown(int keyCode, KeyEvent event) {
30:		    if ((keyCode == KeyEvent.KEYCODE_BACK) && webview.canGoBack()) {
31:		    	webview.goBack();

Read More

2:	editText.setOnEditorActionListener(new OnEditorActionListener() {
3:	    @Override
4:	    public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
5:	        boolean handled = false;
6:	        if (actionId == EditorInfo.IME_ACTION_SEND) {

Read More

KeyEvent Class Overview
Object used to report key and button events. Each key press is described by a sequence of key events. A key press starts with a key event with ACTION_DOWN. If the key is held sufficiently long that it repeats, then the initial down is followed additional key events with ACTION_DOWN and a non-zero value for getRepeatCount(). The last key event is a ACTION_UP for the key up. If the key press is canceled, the key up event will have the FLAG_CANCELED flag set. Key events are generally accompanied by a key code (getKeyCode()), scan code (getScanCode()) and meta state (getMetaState()). Key code constants are defined in this class. Scan code constants are raw device-specific codes obtained from the OS and so are not generally meaningful to applications unless interpreted using the KeyCharacterMap. Meta states describe the pressed state of key modifiers such as META_SHIFT_ON or META_ALT_ON. Key codes typically correspond one-to-one with individual keys on an input device. Many keys and key combinations serve quite different functions on different input devices so care must be taken when interpreting them. Always use the KeyCharacterMap associated with the input device when mapping keys to characters. Be aware that there may be multiple key input devices active at the same time and each will have its own key character map. As soft input methods can use multiple and inventive ways of inputting text, there is no guarantee that any key press on a soft keyboard will generate a key event: this is left to the IME's discretion, and in fact sending such events is discouraged. You should never rely on receiving KeyEvents for any key on a soft input method. In particular, the default software keyboard will never send any key event to any application targetting Jelly Bean or later, and will only send events for some presses of the delete and return keys to applications targetting Ice Cream Sandwich or earlier. Be aware that other software input methods may never send key events regardless of the version. Consider using editor actions like IME_ACTION_DONE if you need specific interaction with the software keyboard, as it gives more visibility to the user as to how your application will react to key presses. When interacting with an IME, the framework may deliver key events with the special action ACTION_MULTIPLE that either specifies that single repeated key code or a sequence of characters to insert. In general, the framework cannot guarantee that the key events it delivers to a view always constitute complete key sequences since some events may be dropped or modified by containing views before they are delivered. The view implementation should be prepared to handle FLAG_CANCELED and should tolerate anomalous situations such as receiving a new ACTION_DOWN without first having received an ACTION_UP for the prior key press. Refer to InputDevice for more information about how different kinds...
Methods
  • getAction
    Retrieve the action of this key event.
  • getDeviceId
    Gets the id for the device that this event came from.
  • getDownTime
    Retrieve the time of the most recent key down event, in the uptimeMillis() time base.
  • getEventTime
    Retrieve the time this event occurred, in the uptimeMillis() time base.
  • getScanCode
    Retrieve the hardware key id of this key event. These values are not reliable and vary from device to device.
  • getUnicodeChar
    Gets the Unicode character generated by the specified key and meta key state combination.
  • isCanceled
    For ACTION_UP events, indicates that the event has been canceled as per FLAG_CANCELED.
  • isSystem
    Is this a system key? System keys can not be used for menu shortcuts.
  • isTracking
    For ACTION_UP events, indicates that the event is still being tracked from its initial down event as per FLAG_TRACKING.