keylistener

Not sure how to put timer into my keylistener code

落花浮王杯 提交于 2021-02-10 14:17:43
问题 basically, I have a keylistener code (I am aware of keybindings thank you but I don't need that for my project), and it will re-size the window frame based on what you press. However, when you hold down w, it goes like this w [pause] wwwwwwww and it's noticeable whenever you re-size the window. Can someone help me successfully put timer in my code? I've excluded the import statements but they're all there. public class KeyFrame extends JFrame implements KeyListener { public boolean t = true;

My java(JFrame) player movement script won't work

﹥>﹥吖頭↗ 提交于 2021-02-08 09:20:27
问题 I am making a top down 2d survival game where the player must dodge projectiles from enemies in order to survive, but I've run into an issue that may, slightly influence the gameplay of my first real java project, that issue being that the player cannot move in any way shape or form and if the projectiles had of been implemented, then the player would lose immediately after spawning into this world. here is the code: package maximiza; import java.awt.*; import java.awt.event.KeyEvent; import

Handle EditText key change event with input type TEXT

删除回忆录丶 提交于 2021-01-29 20:21:40
问题 My Use case is to restrict user after he has entered 4 lines in text box. Setting maxLines will not work to stop user. I am surprise that Android is not providing key down/up event when input type is InputType.TYPE_CLASS_TEXT . I am receiving event for all other types. Below is my code. EditText et = new EditText(this); et.setMaxLines(3); et.setSingleLine(false); et.setInputType(InputType.TYPE_CLASS_TEXT); et.setHint("First edit text"); et.setKeyListener(this); // This key listener is also

KeyListener doesn't work at all but my code worked fine on my friend's computer

六眼飞鱼酱① 提交于 2021-01-28 04:01:08
问题 KeyListener doesn't work at all it's like it's not there, it shows the frame with the paddle but it doesn't move when arrowkey pressed , BUT my code worked properly on my friend's computer , i deleted and installed the last version of JDK and eclipse and nothing changed , i even compilated it with cmd and it doesn't work edit : one in a 100 tries it works properly then the next time it returns to not working the code is about a paddle that moves with arrowkeys the Paddle class : import java

event.key is undefined in mobile browsers for keyup, keydown and keypress

≯℡__Kan透↙ 提交于 2020-02-29 22:05:41
问题 The following code is supposed to simply suppress any key press and add the pressed key to a div instead. This works fine on desktop, however on mobile (safari and chrome) event.key is undefined. <html> <head></head> <body> <input /> <div id="#test"></div> <script> var str = ''; var el = document.getElementById('#test'); document.addEventListener('keypress', function(event) { str += event.key; event.preventDefault(); el.innerHTML = str; }) </script> </body> </html> event.keyCode and event

Java JTextArea KeyListener

十年热恋 提交于 2020-02-27 06:19:09
问题 When I pressed the ENTER my JTextArea starts a new row and I only want do to the doClick() method nothing else. How should I do that? textarea.addKeyListener(new KeyListener(){ @Override public void keyPressed(KeyEvent e){ if(e.getKeyCode() == KeyEvent.VK_ENTER){ button.doClick(); } } @Override public void keyTyped(KeyEvent e) { } @Override public void keyReleased(KeyEvent e) { } }); 回答1: Use .consume() : Consumes this event so that it will not be processed in the default manner by the source

Java JTextArea KeyListener

跟風遠走 提交于 2020-02-27 06:19:06
问题 When I pressed the ENTER my JTextArea starts a new row and I only want do to the doClick() method nothing else. How should I do that? textarea.addKeyListener(new KeyListener(){ @Override public void keyPressed(KeyEvent e){ if(e.getKeyCode() == KeyEvent.VK_ENTER){ button.doClick(); } } @Override public void keyTyped(KeyEvent e) { } @Override public void keyReleased(KeyEvent e) { } }); 回答1: Use .consume() : Consumes this event so that it will not be processed in the default manner by the source

Java KeyListener keyPressed method fires too fast

亡梦爱人 提交于 2020-01-28 02:28:09
问题 If you use the java KeyListener class you know that if you hold down a key keyPressed will fire one KeyEvent , and then about half a second later will fire the same key many times very very fast. I would like to know if there is a way to keep the KeyEvents from firing too fast. I would like them to be at a nice constant rate of about once every 500 ms. 回答1: You can, but the trick is to not slow down the firing of events, but to slow down how fast you process them: KeyListener kl = new

Java KeyListener keyPressed method fires too fast

我怕爱的太早我们不能终老 提交于 2020-01-28 02:27:13
问题 If you use the java KeyListener class you know that if you hold down a key keyPressed will fire one KeyEvent , and then about half a second later will fire the same key many times very very fast. I would like to know if there is a way to keep the KeyEvents from firing too fast. I would like them to be at a nice constant rate of about once every 500 ms. 回答1: You can, but the trick is to not slow down the firing of events, but to slow down how fast you process them: KeyListener kl = new

KeyPressed and KeyTyped Confusion [duplicate]

蓝咒 提交于 2020-01-25 06:08:26
问题 This question already has answers here : KeyListener, keyPressed versus keyTyped (4 answers) Closed 6 years ago . I have searched about difference between KeyPressed and KeyTyped Events but still I'm not clear about that . One thing I have found is Keypressed is triggered first than KeyTyped . Please clarify me when these are triggered exactly . Which is appropriate to use for which purpose ? Thanks in advance 回答1: keyPressed is fired whenever any key press occurs. keyTyped is fired when a