keycode

Combining keycode events in jQuery

梦想的初衷 提交于 2019-12-22 17:54:11
问题 I'm building a virtual keyboard in jQuery, using keycode events to tigger an append, but keycode combinations are throwing me for a loop. Here's an example: I want to append a questionmark only when both the SHIFT key (keycode 16) and slash key (keycode 191) are pressed together. I thought the && operator would help, but this only appends the slash: $(document).keydown(function(e) { if (e.keyCode == 16 && e.keyCode == 188 ) { $('#mydiv').append('<span>?</span>'); } }); Any suggestions or idea

JavaScript: Avoiding hardcoded keycodes [duplicate]

独自空忆成欢 提交于 2019-12-22 09:11:59
问题 This question already has answers here : Closed 6 years ago . Possible Duplicate: JavaScript event.keyCode constants This is my code: $button.on('keyup', function (event) { // Detect an Enter keypress if(event.keyCode === 13) { doStuff(); } }); As you can see, the keycode 13 is hardcoded. Is there a (cross-browser) way to fish out that number in a more semantically meaningful way? 回答1: If you work with jQueryUI , you may use $.ui.keyCode constants: keyCode: { BACKSPACE: 8, COMMA: 188, DELETE:

jquery键盘事件总结

与世无争的帅哥 提交于 2019-12-22 09:02:06
在工作中在发现同事在写输入密码按键的相关js效果时,发现自己对于这块很是不了解,这几天特地了解了一下,进行以下总结: 一、首先要知道键盘事件的几个属性: 1、keydown():在键盘按下时触发。 2、keyup():是按下键盘起来后的事件。 3、keypress():在敲击按键时触发,我们可以理解为按下并抬起同一个按键。 二、获得键盘上对应的 ascII 码: //键码获取 $(document).keydown(function (event) { alert(event.keyCode); }); 上面例子中,event.keyCode 可以帮助我们获取到我们按下了键盘上的什么按键,它返回的就是 ascII 码,比如说上下左右键,分别是38,40,37,39; 三、案例1: 比如:小说网站中常见的按左右键来实现上一篇文章和下一篇文章; 按 ctrl+enter 实现表单提交(以此提高用户体验); 如果我们要实现 ctrl+enter 提交表单,可以这样: //键盘操作 $(document).keydown(function (event) { if (event.ctrlKey && event.keyCode == 13) { alert('Ctrl+Enter'); }; switch (event.keyCode) { case 37: alert('方向键-左');

使用JS监听键盘按下事件(keydown event)

守給你的承諾、 提交于 2019-12-22 07:28:06
1、监听全局键盘按下事件,例如监听全局回车事件 1  $(document).keydown(function(event){ 2    if(event.keyCode == 13){ 3      alert('你按下了Enter'); 4    } 5  }); 2、监听某个组件键盘按下事件,例如监听id为btn的button组件的回车按下事件 1  $("#btn").keydown(function(event){ 2    if(event.keyCode == 13){ 3      alert('你按下了Enter'); 4    } 5  }); 3、如果是要监听组合键,例如监听ctrl+c 1  $(document).keyup(function(event){ 2    if (event.ctrlKey && event.keyCode === 67){ 3      alert('你按下了CTRL+C'); 4    } 5  }); 4、详细keyCode值列表 来源: https://www.cnblogs.com/pangpanghuan/p/6423204.html

jQuery Trigger keyCode Ctrl+Shift+z & Ctrl+z in wysiwyg textarea

被刻印的时光 ゝ 提交于 2019-12-22 04:57:10
问题 i was wondering how do i trigger the event keyCode composed by Ctrl+z and the event keycode composed by Ctrl+Shift+z ? 回答1: If you want to trigger the event then it should be something like this: HTML <!DOCTYPE html> <html> <head> </head> <body> <input type=button value=CTRL+SHIFT+Z id=bcsz /> <input type=button value=CTRL+Z id=bcz /> <textarea id=t ></textarea> </body> </html> JavaScript var t = document.getElementById('t'), //textarea bcsz = document.getElementById('bcsz'), //button ctrl

Send NSEvent to background app

一笑奈何 提交于 2019-12-22 04:56:16
问题 I need to send the key combo ^⌘C to a background app with the bundle identifier com.company.app . The key combo should then activate a menu item in that application. Unfortunately, I have no clue how to do that. Some research pointed me to the NSEvent and CGEvent API using CGEventPostToPSN() , but I was unable to get it work correctly, as I don't know how to set up the key combo. CGEventPost() didn't seem to work with the events I created, even if the desired app is the active one. Here is

How can I determine if the Backspace has been pressed in the KeyPress event?

北慕城南 提交于 2019-12-22 04:24:16
问题 This: http://msdn.microsoft.com/en-us/library/system.windows.forms.control.keypress.aspx ...indicates that I should have access to e.KeyCode in the KeyPress event, but I don't seem to. I'm trying to allow only 1,2,3, and backspace: private void textBoxQH1_KeyPress(object sender, KeyPressEventArgs e) { if ((e.KeyChar != '1') && (e.KeyChar != '2') && (e.KeyChar != '3') && (e.KeyChar != (Keys.Back))) { e.Handled = true; } } ...but "e." does not show a "KeyCode" value like the example shows, and

JavaScript keycode allow number and plus symbol only

纵饮孤独 提交于 2019-12-22 03:55:24
问题 I have this JavaScript function that is used to force user only type number in the textbox. Right now and I want to modify this function so it will allow the user to enter plus (+) symbol. How to achieve this? //To only enable digit in the user input function isNumberKey(evt) { var charCode = (evt.which) ? evt.which : event.keyCode if (charCode > 31 && (charCode < 48 || charCode > 57)) return false; return true; } 回答1: Since the '+' symbol's decimal ASCII code is 43, you can add it to your

Javascript numberpad keycode parsing

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-20 12:28:53
问题 I am attempting to parse keydown events from the numberpad with the following: $('#myDiv').keydown(function(e) { val = String.fromCharCode(e.which) }); The problem is that keypad 0-9 return keyCodes of 96-105 which, according to fromCharCode() are the lower case letters a-i . How do I get keydown events of the numberpad to resolve to the appropriate number? 回答1: You don't: you use the keypress event. The keypress event is the only event that will give you reliable information about typed

KeyboardEvent.keyCode deprecated. What does this mean in practice?

女生的网名这么多〃 提交于 2019-12-20 08:24:09
问题 According to MDN, we should most definitely not be using the .keyCode property. It is deprecated: https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/keyCode On W3 school, this fact is played down and there is only a side note saying that .keyCode is provided for compatibility only and that the latest version of the DOM Events Specification recommend using the .key property instead. The problem is that .key is not supported by browsers, so what should we using? Is there something I