keypress

Close ModalWindow on keypress

杀马特。学长 韩版系。学妹 提交于 2019-12-04 05:21:14
I would like to be able to close a ModalWindow when the user presses a key, in my case ESC. I have a Javascript listener for the keypress which calls the click event of the cancel button's ID: jQuery("#"+modalWindowInfo.closeButtonId).click(); Is this the correct way to do it? I am wondering because it works in Chrome but not in FF, but it could be due my specific implementation. tetsuo The 'right' way to do it is to call the server, then close it with the response. You can do this with an ajax behavior: ModalTestPage.java public class ModalTestPage extends WebPage { public ModalTestPage

Only allow numbers, decimals, negative

狂风中的少年 提交于 2019-12-04 05:01:57
问题 I have this code that only permits numbers to be entered in an input field on keypress() if (e.which != 8 && e.which != 0 && (e.which < 48 || e.which > 57)) { return false; } How can I also allow decimals, and minus keypress? 回答1: This is a solution, but I recommend to use mask plugin, for example: jQuery-Mask-Plugin $("#id").keypress(function(e){ if (e.which != 46 && e.which != 45 && e.which != 46 && !(e.which >= 48 && e.which <= 57)) { return false; } }); <script src="https://ajax

Excluding form fields from keypress handler assigned to body

陌路散爱 提交于 2019-12-04 04:27:21
问题 I have a keypress handler on a web page assigned to the body element. I really do want it to be active anywhere in the web page. Or so I thought. The keypress events in textual input forms also activate the body handler, which makes sense, but which I don't want. Ideally, I'd like to keep the keypress handler assigned to the body element and somehow exclude just the input forms. Is there any way I can stop the event at the input level and prevent it from propagating to body? (Or is that even

AngularJS backspace keypress

柔情痞子 提交于 2019-12-04 02:25:11
I need to capture user's backspaces inside an input. So I've done this: <input type="text" ui-keypress="{8:'removeTagOnBackspace()'}" ng-model="searchStudent" /> And then, inside my controller I've done this, just to check if it's working: $scope.removeTagOnBackspace = function() { console.log('here'); }; But is not printing anything. What is wrong with this? Is angular able to capture backspaces? Got it! <input type="text" ng-keydown="removeTagOnBackspace($event)" /> And: $scope.removeTagOnBackspace = function (event) { if (event.keyCode === 8) { console.log('here!'); } }; 来源: https:/

Send key code to command line program on OS X

你说的曾经没有我的故事 提交于 2019-12-04 01:57:17
问题 I want to make a script that starts a program and then sends it key input. In psuedo-script: #!/bin/bash ./program << (PRESS CONTROL-Z) The program is running so if there were additional commands in the script they will not be reached unless say control-z terminates the program. Is this possible? From what I've found I thought it might require key codes but I could be wrong. 回答1: You might be looking for expect (from http://expect.nist.gov/). This deals with the complexities of pseudo-ttys

Detect enter in input elements of a certain class

隐身守侯 提交于 2019-12-04 00:30:17
I need to detect when someone hits "enter" in text inputs with a specific class. My jQuery is as follows: $('input.large').keypress(function (e) { if(e.which ==13) console.log("pressed enter"); }); My HTML is something like this: <tr><td> Personal Name </td></tr> <tr><td> <input type='text' class='large'> </td></tr> <tr><td> Email</td></tr> <tr><td> <input type='text' class='large'> </td></tr> When I've given the fields IDs and tried $('#elementid').keypress it worked. But this isn't working. I get no console output. What am I missing? You can use live ( .on() ) events in document with keydown

Invoke keypress event in android?

家住魔仙堡 提交于 2019-12-03 20:56:09
I need to invoke a key press event in android . Any suggestions ????? You need to use the instrumentation class : Instrumentation i = new Instrumentation(); i.sendKeyDownUpSync(KeyEvent.KEYCODE_A); This should be equivalent to a A pressed on the keyboard. The following example shows how to invoke Key Back key event: KeyEvent eventDown = new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_BACK); KeyEvent eventUp = new KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_BACK); dispatchKeyEvent(eventDown); dispatchKeyEvent(eventUp); 来源: https://stackoverflow.com/questions/3361281/invoke-keypress-event

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

这一生的挚爱 提交于 2019-12-03 20:46:57
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 type the space as a first character? You can do this by checking if key is space and selection start is

jQuery .keypress & .keydown .which

混江龙づ霸主 提交于 2019-12-03 18:39:50
问题 Ok so what is the difference in .keypress and .keydown/.keyup? At present I am using .keydown which returns a .which value of 38 for my key, now if i change it to .keypress it returns a value of 109 for that same key. What is the difference and why are the values different for the same key? 回答1: If you press a button it fires a keydown and releasing it fires a keyup . The keypress usually comes between those two. keydown and keyup talk about which key has been changed. keypress tells which

Simulate TAB keypress event in Selenium RC

为君一笑 提交于 2019-12-03 15:41:39
问题 I need to simulate a tab keypress in Selenium RC, using the Java API. I do this after having entered some text using: selenium.type(input, "mytext"); I've tried 3 alternatives to get the tab working: selenium.keyPress(input, "\\9"); and: selenium.focus(input); selenium.keyPressNative("09"); and even: selenium.getEval("var evt = window.document.createEvent('KeyboardEvent');evt.initKeyEvent ('keypress', true, true, window,0, 0, 0, 0,0, 9,0);window.document.getElementsByTagName('input')[2]