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
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
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: getDevice
17:	KeyEvent keyEvent = new KeyEvent(1, 2); 
-
19:	assertThat(keyEvent.getDevice().getName()).isEqualTo("myDevice"); 
Full Snippet Info
7
CodeRank
This code example shows how to use the following methods: sendKeySync
114:	getInstrumentation().sendKeySync(new KeyEvent(KeyEvent.ACTION_UP, 
115:	KeyEvent.KEYCODE_VOLUME_DOWN)); 
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
This code example shows how to use the following methods: getKeyCode, isDown
70:	int keyCode = event.getKeyCode(); 
-
75:	return event.isDown() ? mDialer.onKeyDown(keyCode, event) : 
76:	mDialer.onKeyUp(keyCode, event); 
Full Snippet Info
7
CodeRank
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: sleep
111:	KeyEvent backDown = new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_BACK); 
-
151:	Thread.sleep(TIMEOUT); 
Full Snippet Info
7
CodeRank
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
This code example shows how to use the following methods: getAction
87:	if (event.getAction() != KeyEvent.ACTION_UP) { 
Full Snippet Info
7
CodeRank
This code example shows how to use the following methods: getAction, getKeyCode
97:	int action = event.getAction(); 
98:	int keyCode = event.getKeyCode(); 
-
105:	return super.dispatchKeyEvent(event); 
Full Snippet Info
7
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(); 
-
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, 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, 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, getRepeatCount
47:	if (event.getAction() == KeyEvent.ACTION_DOWN && 
48:	event.getRepeatCount() == 0 && action(CLICK, widget, buffer)) { 
Full Snippet Info
7
CodeRank
This code example shows how to use the following methods: getAction
44:	if (event == null || event.getAction() == KeyEvent.ACTION_UP) { 
Full Snippet Info
7
CodeRank
This code example shows how to use the following methods: getKeyCode
32:	return pref.onKey(null, event.getKeyCode(), event); 
Full Snippet Info
7
CodeRank
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
This code example shows how to use the following methods: getKeyCode
58:	if ( imm.isActive () && event.getKeyCode () == KeyEvent.KEYCODE_BACK ) { 
Full Snippet Info
7
CodeRank
This code example shows how to use the following methods: getAction, getKeyCode
66:	boolean down = event.getAction() == KeyEvent.ACTION_DOWN; 
67:	switch (event.getKeyCode()) { 
Full Snippet Info
7
CodeRank
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, 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:
176:	KeyCharacterMap.VIRTUAL_KEYBOARD, 0, 0, InputDevice.SOURCE_KEYBOARD)); 
Full Snippet Info
6
CodeRank
This code example shows how to use the following methods: sendKeySync
104:	getInstrumentation().sendKeySync(new KeyEvent(KeyEvent.ACTION_DOWN, 
105:	KeyEvent.KEYCODE_POWER)); 
Full Snippet Info
7
CodeRank
This code example shows how to use the following methods: handleKeyDown, getMetaState, getUnicodeChar
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
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
This code example shows how to use the following methods: sleep
112:	KeyEvent backUp = new KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_BACK); 
-
151:	Thread.sleep(TIMEOUT); 
Full Snippet Info
7
CodeRank
This code example shows how to use the following methods: getRepeatCount
18:	if (keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0) { 
Full Snippet Info
6
CodeRank
This code example shows how to use the following methods: getAction, getKeyCode, getRepeatCount
245:	if (mThemeView == null) return super.dispatchKeyEvent(event); 
-
249:	if (event.getRepeatCount() == 0 && 
250:	event.getAction() == KeyEvent.ACTION_DOWN) 
-
252:	switch(event.getKeyCode()) 
-
263:	return super.dispatchKeyEvent(event); 
Full Snippet Info
6
CodeRank
This code example shows how to use the following methods:
103:	a.onKeyDown(KeyEvent.KEYCODE_BACK, new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_BACK)); 
Full Snippet Info
6
CodeRank
This code example shows how to use the following methods: getKeyCode
70:	if (event.getKeyCode() == KeyEvent.KEYCODE_BACK) { 
Full Snippet Info
6
CodeRank
This code example shows how to use the following methods: getAction
73:	if (event == null || event.getAction() == KeyEvent.ACTION_UP) { 
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
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
This code example shows how to use the following methods: isCtrlPressed
46:	else if (event.isCtrlPressed()) { 
Full Snippet Info
6
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
This code example shows how to use the following methods: getRepeatCount
96:	if(event.getRepeatCount() >= LONGPRESS_REPEATS){ 
Full Snippet Info
6
CodeRank
This code example shows how to use the following methods: getAction, getKeyCode
77:	boolean up = event.getAction() == KeyEvent.ACTION_UP; 
78:	switch (event.getKeyCode()) { 
Full Snippet Info
6
CodeRank
This code example shows how to use the following methods: getAction
30:	if ((event.getAction() == KeyEvent.ACTION_DOWN) && (keyCode == KeyEvent.KEYCODE_ENTER)) { 
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
This code example shows how to use the following methods: getAction, getKeyCode
165:	if (event.getAction() != KeyEvent.ACTION_DOWN) { 
-
168:	switch (event.getKeyCode()) { 
Full Snippet Info
6
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
This code example shows how to use the following methods: getAction
162:	if (event.getAction() == KeyEvent.ACTION_UP && keyCode == KeyEvent.KEYCODE_MENU) { 
Full Snippet Info
6
CodeRank
This code example shows how to use the following methods: getAction
109:	if (grabKeyCode && event.getAction() == KeyEvent.ACTION_DOWN && keyCode != 0 && keyCode < key_labels.length) 
Full Snippet Info
6
CodeRank
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

See Code Examples for Android KeyEvent Methods: