keydown

Android - capture/suppress Home and EndCall buttons events?

旧城冷巷雨未停 提交于 2019-11-28 02:26:06
If you ever tried to write a locker app on Android sure you meet this problem: boolean mBackPressed = false; @Override public boolean onKeyDown(int keyCode, KeyEvent event) { if (event.getAction() == KeyEvent.ACTION_DOWN) { switch (keyCode) { case KeyEvent.KEYCODE_BACK: mBackPressed = true; break; case KeyEvent.KEYCODE_MENU: if (mBackPressed) unLock(); break; default: mBackPressed = false; showMessage(); break; } } return true; } private void showMessage() { Toast.makeText(getBaseContext(), "Back + Menu", Toast.LENGTH_SHORT) .show(); } private void unLock() { this.setResult(Activity.RESULT_OK)

Detect Arrow Key - KeyDown for the whole window

℡╲_俬逩灬. 提交于 2019-11-27 23:00:24
I have a WinForms Form (C#/.Net) and it contains a PictureBox, MenuStrip, Panel and two Button controls. I need to detect KeyDown event for the Arrow Keys for the whole window; i.e., when the window is in the foreground, regardless of which one of the child controls has the focus, I need to know when an arrow key is pressed and execute some code when it happens. I don't want to go and attach an event handler for each control. Is there a better way? How can I do it? Edit: Using KeyPreview as suggested by an answer below, I am able to detect other keys. Not able to detect arrow keys. I am able

How do i capture the Print Screen key?

谁说我不能喝 提交于 2019-11-27 22:37:10
I my program I need to capture when the Print Screen key is pressed down but it is not working (however it works with other keys). I guess this has something to do with windows hijacking my authority and since im still new at this I'd love to know how I can get around this issue. Here's my current code: namespace Boom_Screenshot_ { /// <summary> /// Interaction logic for Window1.xaml /// </summary> public partial class Window1 : Window { //SETTINGS Key TRIGGER_KEY = Key.PrintScreen; public Window1() { InitializeComponent(); } private void Window_KeyDown(object sender, KeyEventArgs e) { if (e

KeyboardEvent in Chrome, keyCode is 0

≯℡__Kan透↙ 提交于 2019-11-27 20:28:33
I am trying to set keyCode on dispatched event object . On button click, event is raised on textbox control to simulating keydown event. Event is raised successfully, but keyCode is 0. I need to send event object with correct keyCode to textbox. I've been using code from here . How to set keyCode value in dispatched event? <html> <head> </head> <body> <input type="button" id="btn" value="Click"></input> <input type="text" id="txt"></input> <script> document.getElementById('btn').addEventListener("click", btnClick); document.getElementById('txt').addEventListener("keydown", txtKeydown);

KeyDown : recognizing multiple keys

只谈情不闲聊 提交于 2019-11-27 20:02:30
How can I determine in KeyDown that Ctrl Up was pressed. private void listView1_KeyDown(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.Control && e.KeyCode == Keys.Up) { //do stuff } } can't work, because never both keys are pressed exactly in the same second. You always to at first the Ctrl and then the other one... You can check the modifiers of the KeyEventArgs like so: private void listView1_KeyDown(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.Up && e.Modifiers == Keys.Control) { //do stuff } } MSDN reference Matt Hamilton From the MSDN page on KeyEventArgs : if (e

What's the theory behind jQuery keypress, keydown, keyup black magic (on Macs)? [closed]

浪子不回头ぞ 提交于 2019-11-27 17:12:46
I am confused about the various behaviors of keypress , keydown , and keyup . It seems that I have missed an important piece of documentation, one that explains the subtleties and nuances of this trio. Could someone help me to figure out which document I need to read in order to more effectively use these events? In case you want details, see below. @o.v.: you asked me to show some code, but it's not really a specific problem in the code that I'm trying to solve. I'm trying to get a handle on the behaviors of these event handlers and asking someone who understands them to point me to a good

keydown event new value

淺唱寂寞╮ 提交于 2019-11-27 16:18:33
问题 Browser: Google Chrome V19.0.1084.52 I have a textbox which needs to be a number less than or equal to 255, on keydown I want to check if this value is above or equal to 255 else prevent the event. In the Console when I console.log the event it will show event.srcElement.value as the value will appear i.e. from 12 => 123, when I console.log just event.srcElement.value it will show as the input was, not will be. Console.log's are happening one after the other, nothing in between, no pauses.

Simulate pressing tab key with jQuery

我怕爱的太早我们不能终老 提交于 2019-11-27 15:35:52
问题 I have some textboxes on a .net-page and want to achieve the following with jQuery: if the user presses return, the program should behave "as if" he had used the tab key, thus, selecting the next element. I tried the following code (and some more): <script type="text/javascript"> jQuery(document).ready(function () { $('.tb').keypress(function (e) { if (e.keyCode == 13) { $(this).trigger("keydown", [9]); alert("return pressed"); } }); }); <asp:TextBox ID="TextBox1" runat="server" CssClass="tb"

How to disable repetitive keydown in jQuery [duplicate]

最后都变了- 提交于 2019-11-27 15:06:09
This question already has an answer here: Prevent JavaScript keydown event from being handled multiple times while held down 7 answers When user keeps a key pressed, I want the keydown() event get called only once, but its called until user stops pressing the key. Here is what I am trying to do: $(document).keydown(function(event){ var keycode = (event.keyCode ? event.keyCode : event.which); if(keycode == '39'){ $("#box").animate({"left": "+=30px"}, "fast"); } }); So, when user presses right arrow key, I want the div#box to move 30px to the right. It moves but if user keeps key pressed it

Listen to multiple keydowns

冷暖自知 提交于 2019-11-27 14:28:47
I'm trying to let a user move an element on the page using the arrow keys. So far, I have movement working for up/down/left/right, but not for diagonal (two arrow keys pressed simultaneously). My listener looks like this: addEventListener('keydown', function(e){ move = false; x = false; y = false; var keycode; if (window.event) keycode = window.event.keyCode; else if (e) keycode = e.which; switch(keycode){ case 37: move = true; x = 'negative'; //prevent page scroll e.preventDefault() break; case 38: move = true; y = 'negative' //prevent page scroll e.preventDefault() break; case 39: move =