keypress

Capture key press (or keydown) event on DIV element

我是研究僧i 提交于 2019-12-16 23:57:32
问题 How do you trap the keypress or key down event on a DIV element (using jQuery)? What is required to give the DIV element focus? 回答1: (1) Set the tabindex attribute: <div id="mydiv" tabindex="0" /> (2) Bind to keydown: $('#mydiv').on('keydown', function(event) { //console.log(event.keyCode); switch(event.keyCode){ //....your actions for the keys ..... } }); To set the focus on start: $(function() { $('#mydiv').focus(); }); To remove - if you don't like it - the div focus border, set outline:

How to find out what character key is pressed?

别来无恙 提交于 2019-12-16 20:15:46
问题 I would like to find out what character key is pressed in a cross-browser compatible way in pure javascript. 回答1: "Clear" JavaScript: <script type="text/javascript"> function myKeyPress(e){ var keynum; if(window.event) { // IE keynum = e.keyCode; } else if(e.which){ // Netscape/Firefox/Opera keynum = e.which; } alert(String.fromCharCode(keynum)); } </script> <form> <input type="text" onkeypress="return myKeyPress(event)" /> </form> JQuery: $(document).keypress(function(event){ alert(String

Setting focus on stored previous element with Shift + Tab

狂风中的少年 提交于 2019-12-14 04:07:49
问题 I am trying to set focus back to the previously focused page element using Shift + Tab keys to set the focus on the previously focused element within the data grid, whether that be a header cell or body cell. It is currently pushing the focus back to the header cells, I suspect because they have a tab index. I'm using the following that should be looking for the stored previously active element, and applying focus-visible class back to it: document.querySelector('.ag-body').tabIndex=0;

Sending “ARROW KEY” key through serial port

一个人想着一个人 提交于 2019-12-14 03:53:36
问题 In the same way that the question Sending “ENTER” key through serial port how can i send the "ARROW key" through the serial port? Most particuly the UP arrow key. 回答1: Cursor keys are a relatively new feature of keyboards. They didn't yet exist at the time the ASCII codes were chosen. Which was largely based on the capabilities of teletypes that were used at that time. Like the widely used ASR-33, its keyboard layout looked like this: No cursor keys. Note how line-feed was a separate key back

breaking loop with keypress in linux c

假装没事ソ 提交于 2019-12-14 03:52:03
问题 I need to write a program in C language which will be doing something like this: For example, when I will press "a", terminal will be writing that typed character in the unending loop like this: aaaaaaaaaaaaaaaa...until another key, for example "b" will be pressed. Final output should look like this: aaaaaaaaabbbbbbq (q should terminate the program). My code here: int main(int argc, char** argv) { int c; static struct termios staryTermios, novyTermios; tcgetattr(STDIN_FILENO, &staryTermios);

KeyPress event doesn't trigger on WinForm UserControl

99封情书 提交于 2019-12-14 03:15:31
问题 I have a user control in my winforms application with this code in the KeyPress event: private void txtCodigo_KeyPress(object sender, KeyPressEventArgs e) { if ((this.txtCodigo.Text.Length == 0) && (e.KeyChar == '\r')) { this.Limpiar(); if (LimpiarEvento != null) LimpiarEvento(this, new EventArgs()); if (NextControl != null) NextControl(this, new EventArgs()); } if ((this.txtCodigo.Text.Length > 0) && (e.KeyChar == '\r')) this.txtCodigo_Leave(sender, e); if (NUMEROS.IndexOf(e.KeyChar) < 0) {

Flex 3: Key press combination to trigger an event/function

空扰寡人 提交于 2019-12-14 02:43:07
问题 Within a specific canvas, I would like a user to be able to press a combination of keys which will trigger an event.(a bit like a cheat in an old megadrive game). Not sure where to start though. Anyone know if it is possible and if so could you give me a clue with how to start? Thanks in advance! 回答1: You can add an eventListener to the top level application for the KeyboardEvent.KEY_DOWN event and check for key combinations there. From this article: <mx:Application xmlns:mx="http://www.adobe

Why does my KeyPressEvent not work with Right/Left/Up/Down?

筅森魡賤 提交于 2019-12-14 02:28:11
问题 In C#, I am trying to see if the user presses the right key so that a player moves right, but when I try it, it does not register the keypress: private void KeyPressed(object sender, KeyPressEventArgs e) { if(e.KeyChar == Convert.ToChar(Keys.Right)) { MessageBox.Show("Right Key"); } } It does not display the MessageBox This doesn't work for Left/Up/Down either However, if I replace it with if(e.KeyChar == Convert.ToChar(Keys.Space)) It works. Am I doing something wrong? 回答1: You should use

Python: sending key press events over SSH

回眸只為那壹抹淺笑 提交于 2019-12-14 01:26:42
问题 I am trying to find out how to simulate key press events on remote server (wich has no X.org aboard) using Python 2.7 Paramiko module. I need to send F2 and Enter consequentially. According to this discussion I have implemented this code: import paramiko client = paramiko.SSHClient() client.connect(...) channel = client.get_transport().open_session() channel.get_pty("vt100") channel.settimeout(100) Assuming that F2 is equal to the '\e[12~' Python string (this follows from mentioned answer and

C++ Generating Key Combinations WINAPI (Without MFC)

霸气de小男生 提交于 2019-12-13 06:51:22
问题 I am trying to get my application to output a key combination ( ALT + D ) to focus on Internet explorers address bar, but I am having trouble implementing the code needed. I already have a method to pass 1 key: void GenerateKey(int vk, BOOL bExtended) { KEYBDINPUT kb = {0}; INPUT Input = {0}; /* Generate a "key down" */ if (bExtended) { kb.dwFlags = KEYEVENTF_EXTENDEDKEY; } kb.wVk = vk; Input.type = INPUT_KEYBOARD; Input.ki = kb; SendInput(1, &Input, sizeof(Input)); /* Generate a "key up" */