keydown

JavaScript: input validation in the keydown event

守給你的承諾、 提交于 2019-12-06 01:47:59
问题 I'm attempting to do info validation against user text input in the process of keydown event. The reason that I am trying to validate in the keydown event is because I do not want to display the characters those that are considered to be illegal in the input box at the beginning. The validation I am writing is like this, function validateUserInput(){ var code = this.event.keyCode; if ((code<48||code>57) // numerical &&code!==46 //delete &&code!==8 //back space &&code!==37 // <- arrow &&code!=

Concat KeyDown event (Keys) to one C# (wpf) string

◇◆丶佛笑我妖孽 提交于 2019-12-06 00:57:20
问题 I have a magnetic card reader that uses the keyboard input to send data. I am using a KeyDown event where I get this object (C# WPF): KeyEventArgs e I want to take the keys that I get and make them one string. I tried to concat e.Key.ToString() , but that doesn't work. My input has lots of numbers and signs (such as ; ? = etc.), and the e.Key.ToString() thing doesn't work (it gives me D3 for a number, and SHIFT or CTRL + another key for the signs). I just want the string, so when I use for

Javascript keyup doesn't work as expected, it executes in instances where I have not removed my finger from a button

╄→尐↘猪︶ㄣ 提交于 2019-12-05 21:54:58
I'm trying to create a simple game in javascript and I'm stuck on how to deal with keys. Small example: function keyUpEvent(event) { alert(event.keyCode); } window.addEventListener("keyup", keyUpEvent, false); I'm running Ubuntu 9.10 and testing it in Firefox 3.5 and Chromium. If I press and release a button instantly I get an alert, which is to be expected, but when I press and hold a button I get a small pause and then a series of alert windows, the expected result is that I only get an alert window when I remove my finger from a button. I reason it has something to do with the fact that

silverlight keydown event doesn't fire for arrow keys

强颜欢笑 提交于 2019-12-05 16:39:01
I have a canvas inside a scrollview. I attached a keydown event handler to the scrollview. For most keys, the handler gets called. However, for the arrow keys, the handler does not get called. Instead, the scrollview gets scrolled in the appropriate direction. I also attached a keyup handler to the scrollview and the keyup does get called for the arrow keys. Is there any way to get the arrow key down event here? Just use the KeyUp event. Works like a charm. I found this silly hack to make it work. Setting the scrollview to not be a tabstop keeps it from eating the key events.. but then I had

Keep focus on textbox after pressing enter

无人久伴 提交于 2019-12-05 07:47:25
How can I keep the focus in a textbox after pressing enter in a VBA form? This code adds the text to a Listbox and I want to keep the focus on the textbox to get ready to receive another item. When I click in the button Add, it adds the text to the Listbox and returns the focus to the textbox, howerver when I press enter it doesn't, even tough it uses the same code. Any suggestion? This is my code for the textbox: Private Sub TxtOtherAsset_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer) If KeyCode = 13 Then CmdAddOtherAsset_Click End If End Sub and this is the code for

How to disable/remove only first space on input field?

别来无恙 提交于 2019-12-05 05:58:03
问题 Good morning everybody! I have a case, when I should prevent users to entering space as a first character on input field. I have a demo here: http://jsbin.com/foyetolo/2/edit It works only when you hit spacebar for first time. When you start typing other characters and select whole text in input (ctrl+a) and then hit the space bar it adds the space in the beginning of input field. So, how to check if on keypress/keydown if the first character will be a space, return false and not allow it to

How to set an evenHandler in WPF to all windows (entire application)?

∥☆過路亽.° 提交于 2019-12-05 03:33:06
问题 How can I set an event handler (such as keydown ) to entire solution, not a single window? 回答1: Register a global event handler in your application class (App.cs), like this: public partial class App : Application { protected override void OnStartup(StartupEventArgs e) { base.OnStartup(e); EventManager.RegisterClassHandler(typeof(Window), Window.KeyDownEvent, new RoutedEventHandler(Window_KeyDown)); } void Window_KeyDown(object sender, RoutedEventArgs e) { // your code here } } This will

Keys pressed at the same time

拟墨画扇 提交于 2019-12-05 02:21:42
问题 Can I know the number of keys pressed at the same time in Javascript? If so, how can I have an array of their keyCode ? 回答1: You can listen for keydown and keyup events. var keys = { length: 0 }; document.onkeydown = function(e){ if(!keys[e.keyCode]) { keys[e.keyCode] = true; keys.length++; } } document.onkeyup = function(e){ if(keys[e.keyCode]) { keys[e.keyCode] = false; keys.length--; } } Then all the keys that are true are the ones that are pressed currently. Fiddle demo thanks to

Convert received keys in PreviewKeyDown to a string

只谈情不闲聊 提交于 2019-12-04 17:44:46
I am using PreviewKeyDown event on a window to receive all the keys from a barcode scanner. The KeyEventArgs is an enumeration and does not given me the actual string. I dont want to use TextInput as some of the keys may get handled by the control itself and may not bubble up to the TextInput event. I am looking for a way to convert the the Keys that I get in PreviewKeyDown to actual string. I looked at the InputManager, TextCompositionManager etc but I am not finding a way where I give the list of keys and it comes back with a string. TextCompositionManager or something must be converting

JavaScript : Simulate Key Events into Textbox/Input

拜拜、爱过 提交于 2019-12-04 10:49:41
问题 Despite many article on SO on how to simulate key presses (keydown/keypress) in JS, no one solution seems to be working with the browsers I'm using (Firefox ESR 17.0.7, Chrome 28.0.1500.72, IE 10). The solutions I have tested were taken from here, here, and here. What I'm trying to do is to simulate ANY keystroke in a textarea / input. While I can append / delete characters directly changing "value", I see no option but input simulation for the keys like "Up", "Down", "Home", and some others.