onkeypress

Javascript Function to enter only alphabets on keypress

旧巷老猫 提交于 2019-11-30 06:48:42
问题 I want to enter only character values inside a <textarea> and numeric values in another. I have been able to make a JavaScript function which only allows numeric values to be entered in the <textarea> using onkeypress . This works in Firefox and Chrome. For alphabets I am creating another JavaScript function using windows.event property. Only problem is this works only in Chrome and not in Firefox. I want to know how to allow only alphabets to be entered using onkeypress event as used for

action by key press

懵懂的女人 提交于 2019-11-29 21:05:26
问题 I'm designing a web based accounting software. I would like to open the "new accounting document" whenever the user press N key for example. And open "settings" whenever he/she is pressing S key. I saw some scripts based on JavaScript and jQuery. But they did not work exactly. Can anyone help me please ? I have tried this script: var code = (e.keyCode ? e.keyCode : e.which); if(code == 13) { //Enter keycode //Do something } 回答1: $(document).bind('keyup', function(e){ if(e.which==78) { // "n"

C++: execute a while loop until a key is pressed e.g. Esc?

大憨熊 提交于 2019-11-29 14:27:39
问题 Does anyone have a snippet of code that doesn't use windows.h to check for a key press within a while loop. Basically this code but without having to use windows.h to do it. I want to use it on Linux and Windows. #include <windows.h> #include <iostream> int main() { bool exit = false; while(exit == false) { if (GetAsyncKeyState(VK_ESCAPE)) { exit = true; } std::cout<<"press esc to exit! "<<std::endl; } std::cout<<"exited: "<<std::endl; return 0; } 回答1: Your best bet is to create a custom

Why doesn't keypress handle the delete key and the backspace key

六月ゝ 毕业季﹏ 提交于 2019-11-29 13:40:44
I'm not asking this because I need a work-a-around. I have one that works fine, but I want to know WHY it doesn't. Is this bug in javascript (or JQuery because I was using the JQuery .keypress handler) or is there a specific reason why this is so? Thanks in advance. The keypress event is designed for handling a character typed by the user rather than detecting keyboard activity and the delete and backspace keys do not generate characters. Some browsers blur this line somewhat but the general principle is that the keyup and keydown events are there to detect any key being pressed and telling

How to differentiate between long key press and regular key press?

你离开我真会死。 提交于 2019-11-29 02:05:45
I'm trying to override the functionality of the back key press. When the user presses it once, I want it to come back to the previous screen. However, when the back key is long-pressed (for, let's say, two seconds or more), I want to exit the application. By now, I have overriden these two methods in my activity: @Override public boolean onKeyDown( int keyCode, KeyEvent event){ if (keyCode == KeyEvent.KEYCODE_BACK) { //manage short keypress return true; } return super.onKeyDown(keyCode, event); } @Override public boolean onKeyLongPress( int keyCode, KeyEvent event){ if (keyCode == KeyEvent

Javascript Function to enter only alphabets on keypress

℡╲_俬逩灬. 提交于 2019-11-28 23:42:54
I want to enter only character values inside a <textarea> and numeric values in another. I have been able to make a JavaScript function which only allows numeric values to be entered in the <textarea> using onkeypress . This works in Firefox and Chrome. For alphabets I am creating another JavaScript function using windows.event property. Only problem is this works only in Chrome and not in Firefox. I want to know how to allow only alphabets to be entered using onkeypress event as used for entering only numeric values? function isNumberKey(evt){ <!--Function to accept only numeric values--> /

keyPressEvent.getCharCode() returning 0 for all special keys like enter, tab, escape, etc

萝らか妹 提交于 2019-11-28 18:37:42
My code: @Override public void onKeyPress(KeyPressEvent event) { if (event.getCharCode() == KeyCodes.KEY_ENTER) { registerButton.click(); } } This is attached to a TextBox, and it does fire when I press enter. event.getCharCode() is just zero, not 13 . When I press tab, it's 0 , and when I press escape, it's 0 . Argh! This was working properly yesterday, and something has changed somewhere else in the project to affect this - but I'm not sure what it could be. It really seems like no relevant changes have been made in the last day. If instead I handle a KeyUpEvent , this works as expected. I'm

javascript limit text input characters

亡梦爱人 提交于 2019-11-28 12:16:14
问题 I am wanting to restrict the input characters for a text box to [a-z0-9_-]. However whenever if do this buttons like backspace and the arrow keys don't work. I have found some attempts on this website and others but either they don't work properly on all browsers or they use a black list. For example the W3Schools website example black lists numbers. Is there a way to use white list (the one above) and still allow keys like backspace, arrows, home, end etc? Or do i have to add everyone of the

Why doesn't keypress handle the delete key and the backspace key

牧云@^-^@ 提交于 2019-11-28 07:37:56
问题 I'm not asking this because I need a work-a-around. I have one that works fine, but I want to know WHY it doesn't. Is this bug in javascript (or JQuery because I was using the JQuery .keypress handler) or is there a specific reason why this is so? Thanks in advance. 回答1: The keypress event is designed for handling a character typed by the user rather than detecting keyboard activity and the delete and backspace keys do not generate characters. Some browsers blur this line somewhat but the

jQuery keypress left/right navigation [duplicate]

ぐ巨炮叔叔 提交于 2019-11-27 18:29:21
This question already has an answer here: Binding arrow keys in JS/jQuery 16 answers I want to give my content slider the ability to respond to keypress (LEFT ARROW key and RIGHT ARROW key) feature. I have read about some conflicts between several browsers and operation systems. The user can navigate the content while he is on the global website (body). Pseudo Code: ON Global Document IF Key Press LEFT ARROW THEN animate #showroom css 'left' -980px IF Key Press RIGHT ARROW THEN animate #showroom css 'left' +980px I need a solution without any crossover (Browsers, OSs) conflicts. $("body")