keyevent

Do browser key events fire (bubble) only to elements in focus?

别来无恙 提交于 2019-12-12 23:25:32
问题 Experimental evidence has led me to believe that key (up, down, press) events fire (in bubble phase) only to elements in focus . This behavior may be intuitive, obvious and/or desirable, but haven't seen this documented anywhere, so I was hoping the community would confirm my "theory". Otherwise, I have some code that's not properly letting these events bubble up. Thanks! 回答1: key events are always targeted to the element that has focus, and bubble up until cancelled. You cannot press a key

Get key combinations

一曲冷凌霜 提交于 2019-12-12 07:18:34
问题 How can I get key combination of keys on keyboard E.G. ( Ctrl + somekey , Alt + somekey ) with Java? I use KeyEvent listener, MouseEvent listener for all keys on keyboard. I can catch all key event on keyboard by using that listener. But, I cannot catch key combination such as ( Ctrl + Alt + Del )....etc. 回答1: public void keyPressed(KeyEvent kevt) { if(kevt.getKeyChar()=='c') { if(kevt.isAltDown()) //Code if Alt+c pressed if(kevt.isControlDown()) //Code if Ctrl+c pressed if(kevt.isShiftDown()

Qt mainwindow handle space key press

跟風遠走 提交于 2019-12-12 06:23:16
问题 I am programming a Qt programm and I want to get triggered, when the user presses Space, but it doesn't work. mainwindow.h protected: void keyPressEvent(QKeyEvent* event); mainwindow.m void MainWindow::keyPressEvent(QKeyEvent* event) { qDebug() << event->key(); } Nearly every key is working, except for the space. Could it be possible that the space isn't working, because there is some focus to an UI Element, if yes, how can I fix it? 回答1: uielement->setFocusPolicy(Qt::NoFocus); is one

Android - How can a Service App dispatch KeyEvents to another Foreground App

孤街醉人 提交于 2019-12-12 04:49:19
问题 I want to develop an Android Service app that dispatches KeyEvents to the foreground application. Somehow, it would be like this I cant seem to find a way how, I am only familiar with the activity dispatches KeyEvents to itself, like this: @Override public boolean dispatchKeyEvent(KeyEvent event) { if (event.getAction() == KeyEvent.ACTION_DOWN) { if (event.getKeyCode() == KEYCODE_1) { // Do something } else if (event.getKeyCode() == KEYCODE_2) { // Do something } } else if (event.getAction()

Android listener for return key on EditText not working for every device

你说的曾经没有我的故事 提交于 2019-12-12 04:26:29
问题 I want to initialize a compose field with a listener for the return key. In the documentation it says that actionId will be EditorInfo.IME_NULL if it is being called due to the enter key being pressed. I compared actionId for that value. It also says that if triggered by a returnkey we receive KeyEvent object so i test it for KeyEvent.ACTION_UP which is the value corresponding for the release of a key. When i run the code it works for fine for a device running KitKat but in the other running

Android: No KeyEvent on unfocusable view?

时光毁灭记忆、已成空白 提交于 2019-12-12 03:47:26
问题 In my case, I'm required to intercept all key events before they are dispatched to target. So I installed a KeyListener on every view or widget, Activity.onKey can't satisfy me in the case. However, I found that if view (like RelativeLayout) is not focusable, it won't receive any KeyEvent. And I also got following warnings WARN/KeyCharacterMap(312): No keyboard for id 0 WARN/KeyCharacterMap(312): Using default keymap: /system/usr/keychars/qwerty.kcm.bin If I forced view to be focusable, it's

Stop windows Key Input Delay in Java

旧巷老猫 提交于 2019-12-11 20:59:45
问题 I am creating a side scrolling game and currently when I press an arrow key, the character moves, pauses then moves indefinitely until the key is released. The pause comes from Windows configuration with Key Delay, so you don't accidentally type in duplicate key presses if you hold down the key too long. I want to know if there is a way to get rid of this. Here is my code for key presses: public void keyReleased(KeyEvent ke){} public void keyTyped(KeyEvent ke){} public void keyPressed

Calling the builtin Undo functionality of EditText by sending Ctrl+Z

浪子不回头ぞ 提交于 2019-12-11 16:53:38
问题 I'm trying to execute the builtin Undo functionality of Android EditText (via TextView) by sending Ctrl+Z : public static KeyEvent keyEvent(int keycode, int metaState) { final long currentTime = System.currentTimeMillis(); return new KeyEvent(currentTime, currentTime, KeyEvent.ACTION_DOWN, keycode, 0, metaState); } mEditText.dispatchKeyEvent(keyEvent(KeyEvent.KEYCODE_Z, KeyEvent.META_CTRL_ON | KeyEvent.META_CTRL_LEFT_ON)); However, it does not work (doesn't do anything). If I connect a

Why doesn't the String object display that gets pressed key characters appended to it?

天涯浪子 提交于 2019-12-11 10:10:32
问题 I wrote a Java applet code using Key Event handling to demonstrate Non buffered input in Java. My code is working fine and the output is alright but I'm having trouble accomplishing another objective in this program: in the overriden keyPressed() method, I write the line: showStatus(s); , where s is the global static StringBuffer object which the characters typed from the keyboard are appended to. But the showStatus() method displays text on the status bar of the applet viewer. Therefore, the

How do I call KeyListener and use KeyEvent?

我是研究僧i 提交于 2019-12-11 09:25:06
问题 I am trying to design a simple box that moves around on the screen. I intend to paint it, then when ever I press an arrow key it will change its position and then repaint it. It will keep doing this until it reaches the outer borders, then the code will stop. But I do not know how to create a KeyListener to check for a keytyped. There may be a better way to do this than what I am trying to do, any help would be greatly appreciated. Okay thank you those ideas do help me, but i am also having