key-events

Pygame.key.get_pressed - how to add interval?

我只是一个虾纸丫 提交于 2019-12-25 06:27:21
问题 I have made a simple grid and a simple sprite which works as "player". but when i use arrow keys to move, the character moves too fast as shown in the picture below: and my question is: How do I set delay or Interval after each keypress event to prevent this problem? player.py #!/usr/bin/python import os, sys, pygame, random from os import path from pt import WIDTH,HEIGHT from pygame.locals import * img_dir = path.join(path.dirname(__file__), 'img') class Player(pygame.sprite.Sprite): def _

How do I keep an object moving using arrow keys?

余生颓废 提交于 2019-12-25 04:17:10
问题 I am making a snake game, and I want my snake to be moving continuously once a key is pressed. So, I press the down key, and it keeps moving even if the key is released. Right now, it just moves while the key is being held down. public void keyPressed(KeyEvent e) { if (e.getKeyCode() == KeyEvent.VK_DOWN) { mySegment[0].moveSouth(); repaint(); } else if (e.getKeyCode() == KeyEvent.VK_UP) { mySegment[0].moveNorth(); repaint(); } else if(e.getKeyCode() == KeyEvent.VK_LEFT){ mySegment[0].moveWest

View losing ability to accept key events

风格不统一 提交于 2019-12-25 02:37:30
问题 I'm a little confused over how key events (back key, volume keys) relate to Views in android. Take for example the problem I currently have: Working OK Create Layout (for example, Relative layout) Add View to Layout (A GL SurfaceView) Run app and wait for everything to load (and for GLSurfaceView to be created) Press home key Re-launch app Press back to exit Not Working OK Create Layout (for example, Relative layout) Add View to Layout Run app and press home key before GLSurfaceView is fully

How to detect combination of multiple modifier and non-modifier keys in VB.NET?

╄→尐↘猪︶ㄣ 提交于 2019-12-24 15:33:11
问题 I have tried different solutions given here for the question, but couldn't seem to get around it. I want to detect Shift Ctrl C in a KeyDown event in VB.Net. The KeyPreview property is set to true for my form. What I tried is: If e.Modifiers = (Keys.Shift And Keys.Control) And e.KeyCode = Keys.C Then 'do the action End If Any help would be much appreciated! 回答1: The comment to your question is correct: If (e.KeyCode = Keys.C AndAlso e.Modifiers = (Keys.Control Or Keys.Shift)) Then 'Do what

Key down keycode not return expected string value

好久不见. 提交于 2019-12-23 02:19:59
问题 I have using iframe in my application. I have return string value when i press any key from keyboard. All other keys are returned expected string value except key 219 ,220, 221 . These keys are returned "Û", "Û", "Ý" these values. But i'm expected "[", "]", "\" these string values. How can I get the correct character from those keys? 回答1: keydown and keyup use keycodes that can vary from keyboard to keyboard depending on your input keyboard type (different keyboards for different regions, etc

disable key event when the focus is on autocompletion box of textbox

那年仲夏 提交于 2019-12-19 10:25:33
问题 In my project there is a Form mainForm in which there are two textBoxes txtUserName and txtPassword and also a button btnLogin . I have given the following txtUserName properties: txtUserName Properties AutoCompleteCustomSource - Collection --> Administrator --> Clerk AutoCompleteMode - Suggest AutoCompleteSource - CustomSource btnLogin_Click Event if (txtUserName.Text.Equals("Administrator") && txtPassword.Text.Equals("123")) { //function to access admin features } else if (txtUserName.Text

Get a key from JTextArea

不想你离开。 提交于 2019-12-17 03:20:25
问题 All I want to do, If I'm pressing '{' this key in JtextArea.automatically '}' this will be print also. if(evt.KEY_PRESSED == '{') System.out.print("}"); is this is okay?? 回答1: for listening changes into JTextComponent is there DocumentListener, if you have to need control over inputed Char, sings, whitespace chars or word(s) you have to implements DocumentFilter notice for Chars reservated by programing language(s) you have to use double escapes, \\( instead of ( or \\{ instead of { otherwise

Key combination of characters (non-Ctrl or Alt) in Java

前提是你 提交于 2019-12-11 13:55:17
问题 I'm doing a project that needs to detect if a certain key combination has been pressed. Any keys like Ctrl , Alt , A - Z and 0 - 9 can be used as key combination. I've searched some codes using KeyStroke.getKeyStroke but it seems like it does not allow combinations without a Ctrl , Shift , Alt , etc. My application needs to detect combinations even WITHOUT Ctrl or Alt e.g. just a combination of plain A + B + C . Is this can also be done with KeyStroke.getKeyStroke ? Replies are greatly

Using jna to consume key events

时光总嘲笑我的痴心妄想 提交于 2019-12-11 13:38:42
问题 In one of the applications I am writing i need to consume certain key events so other applications dont process them. In my code i make a com.sun.jna.platform.win32.WinUser.LowLevelKeyboardProc like so: import com.sun.jna.Native; import com.sun.jna.platform.win32.Kernel32; import com.sun.jna.platform.win32.WinDef.HMODULE; import com.sun.jna.platform.win32.WinDef.LRESULT; import com.sun.jna.platform.win32.WinDef.WPARAM; import com.sun.jna.platform.win32.WinUser.HHOOK; import com.sun.jna

How to capture keyboard inputs in my JWindow using Java?

拈花ヽ惹草 提交于 2019-12-11 01:45:46
问题 When i press keyboard with F1 to 12 or 0 to 9 or A to Z (all buttons). I do not see its capturing my keyboard inputs. How do i fix this? public class Boot extends JWindow implements KeyListener { public Boot() { ..... this.addKeyListener(this); .... } public void keyTyped(KeyEvent ke) { System.out.println( ke.getKeyChar()); } public void keyPressed(KeyEvent ke) { System.out.println( ke.getKeyChar()); /* KEY EVENTS */ // KeyEvent.KEY_TYPED // KeyEvent.KEY_PRESSED // int id = id.getId(); }