keydown

Javascript, key press value is always one character behind the latest?

旧城冷巷雨未停 提交于 2019-11-26 22:01:04
问题 If I type 'St', by the time I press the t, if I output the input of textfield.value in the onkeypress / onkeydown functions, I only get 'S'. Why is this? How do I get rid of this lag? 回答1: use the keyup event instead of keypress . keydown will show the before-keystroke value, as will keypress (apparently). 回答2: Within the keypress event, it's still possible to prevent the typed character from registering, so the input's value canot be updated until after the keypress event. You can use the

OSX: Detect system-wide keyDown events?

十年热恋 提交于 2019-11-26 21:26:57
I'm working on an typing-tutor application for Mac OSX that needs to have keystrokes forwarded to it, even when the application is not in focus. Is there a way to have the system forward keystrokes to the app, possibly through NSDistributedNotificationCenter? I've googled myself silly, and haven't been able to find an answer... EDIT: Sample code below . Thanks @NSGod for pointing me in the right direction -- I ended up adding a global events monitor using the method addGlobalMonitorForEventsMatchingMask:handler: , which works beautifully. For completeness, my implementation looks like this: //

Detect Arrow Key - KeyDown for the whole window

吃可爱长大的小学妹 提交于 2019-11-26 21:16:21
问题 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

Changing the keypress

亡梦爱人 提交于 2019-11-26 19:01:09
In an input box or contenteditable=true div, how can I modify a keypress for the letter "a" to return a keybress for the letter "b"? I.e., every time you type the letter "a" in the div, the output is actually the letter "b". I'm not that concerned with a solution that works in IE--just one that works in Safari, Chrome, & FF. In Chrome, I can see that a keypress event has the properties "charCode", "keyCode", and "which", all of which get assigned the keypress event number. If I fire an event on a keypress, I can modify these values, but I can't figure out what to return so that the actual key

How can I capture KeyDown event on a WPF Page or UserControl object?

旧街凉风 提交于 2019-11-26 18:54:49
I have a Page with a UserControl on it. If the user presses Esc while anywhere on Page I want to handle. I thought this would be as easy as hooking up the PreviewKeyDown event, testing for the Esc key, and then handling it. However, when I placed I breakpoint in the event handler I found it was never getting called. I thought perhaps the UserControl might be getting hit, so I tried PreviewKeyDown there... same result. Does anyone know the proper place to test for a KeyDown or PreviewKeyDown on a Page object? Andy I believe that the PreviewKeyDown event is a tunneling routed event, rather than

How to trigger key combo with jQuery

二次信任 提交于 2019-11-26 17:51:20
问题 I have coded some stuff: http://fincha.com/kunden/schmitt/ I zoom in with .css("zoom") but I need the buttons to simulate CTRL + or CTRL - This code isn't working for me: e = jQuery.Event("keydown"); e.which = 50; $("input").trigger(e); Please help! EDIT I actually wanted to zoom-in and zoom-out the whole web page, not just a input field. 回答1: jQuery normalizes modifier keys on events by setting one or more properties on the event object. So, you want to set event.ctrlKey to true , so this

Listen to multiple keydowns

时间秒杀一切 提交于 2019-11-26 16:45:33
问题 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;

Python method for reading keypress?

女生的网名这么多〃 提交于 2019-11-26 15:21:43
I'm new to Python, and I just made a game and a menu in Python. Question is, that using (raw_)input() requires me to press enter after every keypress, I'd like to make it so that pressing down-arrow will instantly select the next menu item, or move down in the game. At the moment, it requires me to like type "down" and then hit enter. I also did quite a lot of research, but I would prefer not to download huge modules (e.g. pygame) just to achieve a single keyDown() method. So are there any easier ways, which I just couldn't find? Edit: Just found out that msvcrt.getch() would do the trick. It

Adding event handler to an iframe using JQuery

こ雲淡風輕ζ 提交于 2019-11-26 14:30:03
问题 I want to assign a keydown event handler to an iframe. Something similar to the pure JS: document.getElementById('iframe_id').contentWindow.addEventListener('keydown',funcName, true); I tried: $(document.getElementById('iframe_id').contentWindow).keydown( function() { // my func }); But it does not work.. Please help! 回答1: contentWindow is the iframe 's window object. You want the iframe 's document instead: $(document.getElementById('iframe_id').contentWindow.document).keydown(function() { /

Cancel the keydown in HTML

别等时光非礼了梦想. 提交于 2019-11-26 12:30:33
问题 How can I cancel the keydown of a specific key on the keyboard, for example(space, enter and arrows ) in an HTML page. 回答1: If you're only interested in the example keys you mentioned, the keydown event will do, except for older, pre-Blink versions of Opera (up to and including version 12, at least) where you'll need to cancel the keypress event. It's much easier to reliably identify non-printable keys in the keydown event than the keypress event, so the following uses a variable to set in