keyevent

How to detect character key presses?

怎甘沉沦 提交于 2020-01-24 04:19:08
问题 I know how to listen for when the ENTER button is pressed in a TextView, as shown in the code below: textView.setOnKeyListener(new View.OnKeyListener() { public boolean onKey(View v, int keyCode, KeyEvent event) { if((event.getAction() == KeyEvent.ACTION_DOWN) && (keyCode == KeyEvent.KEYCODE_ENTER)) { enterPressed(); return true; } return false; } }); However... how do I listen for when a character key (A-Z, 0-9, special characters, etc.), basically everything else other than ENTER, BACKSPACE

C# - System.Windows.Forms.Keys - How to keep application hotkeys in one place

余生长醉 提交于 2020-01-21 05:33:20
问题 I have few "hotkeys" in my application. All "hotkeys" sequences are unique in application scope (so for example F12 key will always fire the same single task). In few places there are handled like here: if (e.Modifiers == Keys.Shift && e.KeyCode == Keys.Delete) { this.Close(); } if (e.Modifiers == Keys.Shift && e.KeyCode == Keys.Up) { if (Program.PerformLogin()) { frmConfigurationSetup frmSetup = new frmConfigurationSetup(); frmSetup.Show(); } } if (e.KeyCode == Keys.F12) { frmAbout formAbout

Intercepting Tab key press to manage focus switching manually

被刻印的时光 ゝ 提交于 2020-01-20 04:18:55
问题 I want to intercept Tab key press in my main window to prevent Qt from switching focus. Here's what I've tried so far: bool CMainWindow::event(QEvent * e) { if (e && e->type() == QEvent::KeyPress) { QKeyEvent * keyEvent = dynamic_cast<QKeyEvent*>(e); if (keyEvent && keyEvent->key() == Qt::Key_Tab) return true; } return QMainWindow::event(e); } This doesn't work, event isn't called when I press Tab . How to achieve what I want? 回答1: The most elegant way I found to avoid focus change is to

How can I perfectly simulate KeyEvents?

扶醉桌前 提交于 2020-01-19 03:44:10
问题 How can I construct my own KeyEvent objects which perfectly (or very closely) match the ones I would receive from a KeyListener when the end-user types something? For example, I have a United Kingdom ISO keyboard layout and to type the " character I press Shift+2 . If I record this on a JFrame with a KeyListener , I receive the following events: java.awt.event.KeyEvent[KEY_PRESSED,keyCode=16,keyText=Shift,keyChar=Undefined keyChar,modifiers=Shift,extModifiers=Shift,keyLocation=KEY_LOCATION

Pass button click event to actionPerformed on key press

筅森魡賤 提交于 2020-01-15 11:54:20
问题 I'm working on a Java assignment that has to be done using AWT. I want a button to trigger by pushing the enter key while the button is in focus. I figured out how to do this in Swing with the doClick() method, but this doesn't seem to work in AWT. So far I'm trying this: button.addActionListener(this); // Passes value from a TextBox to actionPerformed() button.addKeyListener(new KeyAdapter() { public void keyPressed(KeyEvent e) { if(e.getKeyCode()==KeyEvent.VK_ENTER) { actionPerformed(null);

Detecting keydown/up events during HTML5 native drag

折月煮酒 提交于 2020-01-14 09:08:14
问题 I've an element that can be dragged using native HTML5. It has dragstart, drag, and dragend event listeners assigned to it. In addition, I also have keydown and keyup event listeners assigned to document.body element. When dragging the draggable element, ondrag event will fire as expected. When I press & release any key while not dragging anything, document.body keydown/up events will fire. However, if I keydown/up while performing ondrag, the document.body keydown/up event will not fire. Is

Detecting keydown/up events during HTML5 native drag

我是研究僧i 提交于 2020-01-14 09:07:12
问题 I've an element that can be dragged using native HTML5. It has dragstart, drag, and dragend event listeners assigned to it. In addition, I also have keydown and keyup event listeners assigned to document.body element. When dragging the draggable element, ondrag event will fire as expected. When I press & release any key while not dragging anything, document.body keydown/up events will fire. However, if I keydown/up while performing ondrag, the document.body keydown/up event will not fire. Is

Handle arrow key events by setting the focus policy

懵懂的女人 提交于 2020-01-14 04:43:06
问题 I want to handle key events of the arrow keys in my application. I have already read that for doing so the focus must be disabled. I follow this method: PyQt not recognizing arrow keys. Indeed, when calling self.setChildrenFocusPolicy(QtCore.Qt.NoFocus) (as defined in the linked thread and in my source code below) within MyApp.__init__ , hitting an arrow key raises a key event. However, I do not want to keep the focus disabled during the entire runtime of the application but only upon

how to capture key repeats with javascript [duplicate]

[亡魂溺海] 提交于 2020-01-14 02:56:05
问题 This question already has answers here : Prevent JavaScript keydown event from being handled multiple times while held down (7 answers) Closed 3 years ago . i have an asp.net form and an asp:textbox. i have a problem when the user presses and HOLDS a key down. the user selects the text box and then presses and holds '9' until the text box fills with 9s. Is there any way to detect this situation? Is there a way to stop key repeats when the key is held down? 回答1: Using jquery, you could do

android.view.View$OnUnhandledKeyEventListener

て烟熏妆下的殇ゞ 提交于 2020-01-11 17:12:05
问题 I am new to Android Studio and I don't get why my toolbar isn't shown as described by https://developer.android.com/training/appbar/setting-up I know there are already some other questions like mine on stackoverflow but they don't work at my project. Therefore I would be very thankful for fixing this issue. Screenshot: java.lang.ClassNotFoundException: android.view.View$OnUnhandledKeyEventListener at org.jetbrains.android.uipreview.ModuleClassLoader.load(ModuleClassLoader.java:180) at com