keyevent

Android - Listener for hard keys press at background

痞子三分冷 提交于 2019-11-26 23:06:24
问题 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. 回答1: 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

Is it possible to create an Android Service that listens for hardware key presses?

微笑、不失礼 提交于 2019-11-26 21:51:42
I'd like to run an Android background service that will act as a keylistener from the home screen or when the phone is asleep. Is this possible? From semi-related examples online, I put together the following service, but get the error, "onKeyDown is undefined for the type Service". Does this mean it can't be done without rewriting Launcher, or is there something obvious I'm missing? public class ServiceName extends Service { @Override public void onCreate() { //Stuff } public IBinder onBind(Intent intent) { //Stuff return null; } @Override public boolean onKeyDown(int keyCode, KeyEvent event)

Why trigger F11 press event doesn't work?

戏子无情 提交于 2019-11-26 21:35:00
问题 I just read this question: Full Screen Page by pressing button instead of F11 The op asked to replace F11 with other hot keys, so I'm wondering that maybe I can simulate press F11 to get things work. I learned that I can use trigger in JQuery to simulate key press event, so I do something like this: $("body").keyup(function (e) { alert(e.which); }); var e = $.Event("keyup"); e.which = 122; // # Key code of F11 $("body").trigger(e); When I run this, I got the alert says 122, but it seems that

Programmatically trigger a key events in a JTextField?

拈花ヽ惹草 提交于 2019-11-26 18:36:00
问题 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. 回答1: Do not use KeyListener on JTextField simply add ActionListener which will be triggered when ENTER is pressed (thank you @robin +1 for advice)

Simulate a key held down in Java

寵の児 提交于 2019-11-26 17:09:49
问题 I'm looking to simulate the action of holding a keyboard key down for a short period of time in Java. I would expect the following code to hold down the A key for 5 seconds, but it only presses it once (produces a single 'a', when testing in Notepad). Any idea if I need to use something else, or if I'm just using the awt.Robot class wrong here? Robot robot = null; robot = new Robot(); robot.keyPress(KeyEvent.VK_A); Thread.sleep(5000); robot.keyRelease(KeyEvent.VK_A); 回答1: Thread.sleep() stops

Android: Listen for power key press

感情迁移 提交于 2019-11-26 16:48:04
问题 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

How can a KeyListener detect key combinations (e.g., ALT + 1 + 1)

╄→гoц情女王★ 提交于 2019-11-26 16:38:19
How can I let my custom KeyListener listen for combinations of ALT (or CTRL for that matter) + more than one other key? Assume I have 11 different actions I want the application to do, depending on a combination of keys pressed. ALT + 0 - ALT + 9 obviously don't pose any problems, whereas for ALT + 1 + 0 (or "ALT+10" as it could be described in a Help file or similar) I cannot find a good solution anywhere on the web (or in my head). I'm not convinced that this solution with a timer is the only possible way. Thanks a million in advance for any suggestions! Edit: Actions 0-9 + action 10 = 11

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

假如想象 提交于 2019-11-26 16:29:19
问题 This question already has answers here : Set window to fullscreen (REAL fullscreen; F11 functionality) by javascript (6 answers) Closed 3 years ago . 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

Jquery Run code 2 seconds after last keypress

帅比萌擦擦* 提交于 2019-11-26 15:48:00
问题 I am working on a auto search function for a site. It uses ajax to query an api. At the moment after 3 characters are entered it will search on every key press. What I want is Case1: User enters tes 2 seconds pass search performed Case2: User enters tes 1 second pass user presses t 2 seconds pass search is performed on test Case3: User enters tes 1 second passes user presses t 1.5 seconds pass user presses i 1.5 seconds pass user presses n 1.5 seconds pass user presses g 2 seconds pass search

Fire Form KeyPress event

生来就可爱ヽ(ⅴ<●) 提交于 2019-11-26 12:48:16
问题 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. 回答1: 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: