keyevent

Android - Listener for hard keys press at background

旧时模样 提交于 2019-11-27 21:41:50
Android provides some callback methods which help our to handle key event inside the apps. But what if I want to listen key events when my app is running at background? Eg. I want to listen for long press event on search button to do a special feature. Anup Cowkur KeyEvents can only be handled by Activities as they are the interface to the user pressing the keys and only when they are in the foreground. Even Services that run in the background are not intended to react on user input. But by using a service you can have a workaround. You can create a service that responds to hard key press

Programmatically trigger a key events in a JTextField?

和自甴很熟 提交于 2019-11-27 16:23:15
How do I programmatically trigger a key pressed event on a JTextField that is listening for events on the ENTER ? The listener for key events on my JTextField is declared as follows: myTextField.addKeyListener(new KeyAdapter() { @Override public void keyTyped(KeyEvent e) { if (e.getKeyChar() == KeyEvent.VK_ENTER) { // Do stuff } } }); Thanks. David Kroukamp Do not use KeyListener on JTextField simply add ActionListener which will be triggered when ENTER is pressed (thank you @robin +1 for advice) JTextField textField = new JTextField(); textField.addActionListener(new ActionListener() {

How can I simulate user interaction (key press event) in Qt?

假如想象 提交于 2019-11-27 15:40:36
问题 I need to simulate "Enter" key event in Qt. How can I do this? 回答1: QKeyEvent *event = new QKeyEvent ( QEvent::KeyPress, Qt::Key_Enter); QCoreApplication::postEvent (receiver, event) 回答2: The correct answer might be this: QKeyEvent *event = new QKeyEvent ( QEvent::KeyPress, Qt::Key_Enter, Qt::NoModifier); QCoreApplication::postEvent (receiver, event); in fact there are no matching function for call to QtKeyEvent::QtKeyEvent(Type type, int key) but there is: QtKeyEvent::QtKeyEvent(Type type,

How can I perfectly simulate KeyEvents?

家住魔仙堡 提交于 2019-11-27 14:46:26
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_LEFT,rawCode=16,primaryLevelUnicode=0,scancode=42,extendedKeyCode=0x10] on frame0 java.awt.event.KeyEvent

Android: Listen for power key press

孤街浪徒 提交于 2019-11-27 14:33:17
I am currently trying to listen for when the power button is pressed. Ultimately I would like to have some code run when the power button is pressed twice, to check whether the screen is locked or unlocked. I currently have this: @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); getWindow().addFlags(WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD);//prevent phone from being locked } @Override public boolean onKeyDown(int keyCode, KeyEvent event) { switch (keyCode) { case KeyEvent.KEYCODE_POWER: { Toast.makeText

How to make browser full screen using F11 key event through JavaScript [duplicate]

廉价感情. 提交于 2019-11-27 13:47:47
This question already has an answer here: Set window to fullscreen (REAL fullscreen; F11 functionality) by javascript 6 answers I want to make my browser full screen. Same as when we do F11 key event. I found some examples such as function maxwin() { var wscript = new ActiveXObject("WScript.Shell"); if (wscript!=null) { wscript.SendKeys("{F11}"); } } Which does not work on mozilla or any other latest browsers. Please let me know if there is any way to sort out this problem. Thanks. (In advance.) Treby use this code instead var el = document.documentElement , rfs = // for newer Webkit and

keyCode on android is always 229

◇◆丶佛笑我妖孽 提交于 2019-11-27 08:34:31
On my Samsung Galaxy tab 4 (Android 4.4.2, Chrome: 49.0.2623.105) I ran into a situation where the keyCode is always 229. I've setup a simple test for two situation <div contenteditable="true"></div> <input> <span id="keycode"></span> script: $('div, input').on('keydown', function (e) { $('#keycode').html(e.keyCode); }); DEMO Fortunately I can find posts about this, but I couldn't find one with a working solution. Someone suggested to use keyup instead or to use the textInput event, but that one is only fired on blur . Now, to top it all, this doesn't happen with the default stock browser :(

Fire Form KeyPress event

萝らか妹 提交于 2019-11-27 05:28:47
I have a C# winform, on which I have 1 button. Now, when I run my application, the button gets focus automatically. The problem is KeyPress event of my form does not work because the button is focused. I have tried this.Focus(); on FormLoad() event, but still the KeyPress event is not working. You need to override the ProcessCmdKey method for your form. That's the only way you're going to be notified of key events that occur when child controls have the keyboard focus. Sample code: protected override bool ProcessCmdKey(ref Message msg, Keys keyData) { // look for the expected key if (keyData =

How do I capture Keys.F1 regardless of the focused control on a form?

半世苍凉 提交于 2019-11-27 04:22:22
I used KeyDown event and some simple code like if (e.KeyCode == Keys.F1) to capture F1 is pressed on a form BUT if there are some text boxes on the form or if there are some spreadsheets with Dock Fill on the form then the code above gets useless and does nothing. But I want to do something when user presses F1 on this form. so how do we capture a specific keydown event like F1 on the whole form..and I do not want to go to the route that capture the KeyDown of all other controls on the form and pass them to the Form for processing. is there any cleaner way to do this? Cody Gray Yes, indeed

Key Events in TabActivities?

点点圈 提交于 2019-11-27 02:26:50
问题 I have a TabActivity and want to catch and handle presses of HOME and BACK. Where do I need to catch these events? In my subclass of TabActivity I implement the following: @Override public boolean onKeyDown(int keyCode, KeyEvent event) { switch (keyCode) { // Code handling } return super.onKeyDown(keyCode, event); } Didn't work. So I placed a breakpoint on the switch statement line. But this function never gets called, whether I press volume up/down, menu, home, or back. Where do I need to