Questions tagged [keylistener]
A KeyListener is an implementation of the Observer pattern which is created specifically for handling keyboard events.
1,743
questions
0
votes
0
answers
10
views
KeyListener in Arcanoid
even while trying to solve this problem I read that a much better solution would be to use Key Bindings. Funnily enough, I did try it and it also didn't work so I am now certain there must be a puzzle ...
0
votes
0
answers
20
views
java, combining a kind of keyboard input with operators [closed]
I would like to have a kind of keyboard input where I am able to use operators on.
For example:
String input;
int i;
if (input == "a")
{
i = 1;
}
else if (input == "b")
{
i =...
0
votes
0
answers
34
views
How can I listen to multiple key numbers in Android TV?
I want to change channels using numbers 0-9.
For example, for 391, should I check all digits one by one?
This way I can access many key events:
protected val onKeyDownListener = View.OnKeyListener { ...
0
votes
0
answers
48
views
Keypad listener wont compile
So I’m not able to get this code to compile. I am using an outdated book to learn with and most everything has been working so far. I’ve only ran into a couple of snags that were easy to solve by ...
-1
votes
1
answer
46
views
Moving two rectangles at the same time with different keys Java
Trying to moving two rectangles at the same time with different keys. Using KeyListener. I'm doing Pong Game in Java and have some troubles with this. If I try to move the first paddle, the second ...
-1
votes
1
answer
83
views
Flutter: Submit TextFormField on Enter
I'm working on a desktop application for Windows with Flutter. I want to listen to keyboard keys. I made a Login page and it has two TextFormFields, (one for Username and the other for Password).
When ...
0
votes
1
answer
34
views
KeyListener does not handle keystrokes java
I'm creating a game with a level constructor.According to the idea, the player creates a level with the mouse, places the robot, cargo and loading location, and then moves the robot across the created ...
0
votes
0
answers
35
views
python canvas image not rendered
I followed a few tutorials and I am trying to implement a clean object oriented code for python gui. The idea of my project is opening an image and drawing circles on it with mouse click.
There are 2 ...
0
votes
0
answers
31
views
Why is the JLabel not getting added to the JFrame?
I have tried creating a rocket from a JLabel and also added a KeyListener to it. But when I add it to the JPanel, the rocket does not get displayed in the panel.
But if I solely run the label, the ...
0
votes
0
answers
17
views
Not all key presses are detected
I have this simple code for detecting key presses. The problem is that it doesnt detect all of them even when I press given buttons once per second. Is there a way how to detect for example 3 presses ...
0
votes
1
answer
76
views
How to make JTextField to accept only one letter?
I have an application with multiple text fields I want the text fields to take only one Letter and consume the other. I am trying to do it through ActionListener and KeyAdapter and by making only one ...
0
votes
1
answer
23
views
How to access the objects of the array of JTextField objects in the KeyListener?
I have this code, that use an array of the JTextField objects for 25 elements and I want that ever element will be handle by KeyListener (keyPressed) differently after changing or adding text there.
...
0
votes
1
answer
36
views
Changing the value of a variable using the keyListener in Java
I was working on an exercise where a boolean variable is required to set to true if a certain key is pressed and false otherwise via my class. Later in main, if the value of this variable is true it ...
0
votes
0
answers
27
views
Neither Key Listener nor Document Listener fires for ComboBox
Found a simple JComboBox sample on java2 and expanded it to include both a DocumentListener and KeyListener
hoping to capture keystrokes done within the JComboBox.
Eventually those keystrokes will be ...
0
votes
1
answer
90
views
How to make use of key events USing Intellij IDE and StdDraw as GUI?
I need to make space invaders in java. I am however struggling to implement key events into my program. Currently I have 2 classes, MainMenu.java and FrameListener.java. Noting happens when I press ...
0
votes
0
answers
21
views
Separate User-Input and Graphical-Preview of a Game In Java
I made a simple "snake" game in java. As an exercise I want to control the user-input and the graphical-preview of the game separately using interfaces.
I have created 2 interfaces for that: ...
1
vote
1
answer
45
views
unable to take keyboard inputs in java using KeyListener
i am trying to take keyboard inputs to change the boolean's value but keylisteners are not working
those bolleans values will be used later in other class
heres the method i am having issues with
...
0
votes
0
answers
58
views
My Rectangle moves up despite what key I press with key Listener in Java
I am generally a very bad programmer but have been trying to learn game development for a school project. My problem is that I have a draw method that draws a white rectangle and have a key Listener ...
0
votes
1
answer
232
views
Keyboard listener in SwiftUI: 1-by-1 delivery of keys
I would like to intercept the keyboard input events in a TextField as they come in, i.e. when the user types "Coffee", I want it to trigger 6 events:
C
o
f
f
e
e
Is there a way to do this ...
-1
votes
0
answers
61
views
Can someone please tell me why the key-bindings don't work?
I'm new to java and I'm trying to learn making 2D games. I have done all the things the tutorial guy has done and the keybindings apparently work for him and not for me.
These are the files
main
...
0
votes
1
answer
47
views
Unable to implement keylistener in JComponent
I've been working at the following bit of code for quite some time now, and I just can't seem to get the keyListeners to work. I've tried moving the setFocusable(true), requestFocus(), and ...
0
votes
1
answer
59
views
Is there a way to add a keyListener to JDialog / JOptionPane?
I've been trying to make a game for a school project and wanted to add some easter eggs, but in order to do so I need to detect key input. I've been looking up how to do this for a while and couldn't ...
0
votes
0
answers
91
views
Java Get the last key pressed
I'm trying to make a hotkey to control some code but am struggling to access the last key that has been pressed on the keyboard.
I have this setup to save the key code from the last key press:
import ...
0
votes
0
answers
43
views
Key listener stops working when using images
I want to make a character that moves on the sreen when you use the keyboard. At first I used a white square and it worked without any problems but when I tried to use images it didn't work anymore. ...
0
votes
1
answer
119
views
Android- What is the return key called?
I am currently creating a key listener that runs code when the enter key is pressed. It works on my actual pc keyboard when I run the enter key. The code looks something like this:
...
0
votes
0
answers
51
views
Swing alt+tab to make key listener work again
Is there a way to check what happens in the swinbg directories when I alt+tab?
I have an application, that has a key listener. The listener is added to the JFrame (Scene extends JFrame) since it ...
0
votes
0
answers
25
views
Can i use KeyListener in Console application
I'm making a game that I want to run in a Console Environment and I want to have a none platform-dependent and works whit JDK 16 and modern Operating Systems). So if someone knows of a library for JDK ...
0
votes
1
answer
118
views
How to add JLabel of KeyListener object in Jframe of Main class
I am a bit to new to this Java bit of coding. The problem is that I have a different class for KeyListener and an image that I want to display if the user presses a key, but the image is from JLabel ...
0
votes
1
answer
388
views
Flutter Keyboard Listener builds compounded on each refresh
New to Flutter. I have a keyboard listener wrapping my Scaffold body to detect Enter and backspace key.
I noticed however: upon every page refresh, there will be additional listeners causing double ...
0
votes
2
answers
70
views
How to prevent JColorChooser from absorbing KeyEvents on JComponent?
Here is my probleme.
I have a JComponent in the middle of a slider, itself in the middle of the BorderLayout in a frame.
I use my JComponent to draw/write things in it.
My problem came when I ...
0
votes
1
answer
39
views
Autocomplete delay of JComboBox
I got customized JComboBox which has the ability of autocomplete. It has attached KeyListener where I call HttpClient.send(request) and it returns some result array which I show in dropdown of combo ...
0
votes
1
answer
40
views
How can I check if a user is pressing a specific key i.e. Enter Key Like python's keyboard module?
I am working on making a gui chat app in java (I know too ambitious) that jus sends a message to the connected room. I have not yet done the networking stuff but jus the bare bones gui. I have a text ...
0
votes
0
answers
24
views
Kotlin - Listen For Keys In Background Process
I am writing a Kotlin background process (i.e. No GUI of any sort). The background process plays sound. I want to listen for three keys to achieve different functionalities.
The keys are:
Go to ...
0
votes
2
answers
46
views
Graphics2D and user movement setup
I am testing out graphics movement with simple action and key listener commands, but am struggling to incorporate the Graphics2D class. I am looking to draw an ellipse, which is then controllable ...
0
votes
0
answers
278
views
how do I segregate pynput's keyboard listener to only one window
I am developing a console app and I want to make it so that pynput.keyboard.Listener is only be active when the user has selected the terminal window where the project is running.
I generally have it ...
-1
votes
1
answer
34
views
If I press a third arrow key while holding two others, why does it not run the keyPressed() method?
When I press and hold an arrow key it is sent repeatedly to the keyPressed() method that is part of KeyListener. If I press and hold another arrow key, that arrow key is then repeatedly sent to the ...
0
votes
0
answers
38
views
How do i detect key input?
I am learning to code a game and i was about to code player movement but the key input wasn't working at all. I am following a tutorial and writing everything like in the tutorial so i was very ...
0
votes
1
answer
104
views
Text editor: if certain key pressed want to cancel key event and give new functionality
I have a JEditorPane with text/html type. When an enter key is pressed with the editor focused, I want to do some checks about the state of the document and then override the enter key default ...
1
vote
0
answers
209
views
Python: Listen for keys only when application is in focus
I have a small project on doing a audio-player for the console window. It's all going great, but I'm struggling with one small detail. I want when the user presses a key, space for example, to pause ...
0
votes
0
answers
53
views
Can't kill keyboard listener by killing the entire program
I am writing a website in Bottle framework in which I am using the keyboard listener from pynput. The listener stops only when certain keys are pressed. When I try to kill my program with Ctrl+C (in ...
1
vote
1
answer
57
views
Listener won't be notified when dispatch-ing a KeyEvent (or any kind of event?)
This is not a question for key events in specific. I use KeyEvents/KeyListeners and a JButton as an example. All I want is to be able to fire listeners in JUnit tests conviniently.
I am trying to fire ...
0
votes
1
answer
50
views
Output on keyPressed in JTextArea
When I am trying to get text from JTextArea and print it, it is printing the string after the next key is pressed I want to print it when I press the key.
The code is given below:
textArea_1....
0
votes
0
answers
33
views
Why is JFrame not registering "ESC" being pressed? [duplicate]
In my game, I want the player to be able to press ESC and activate a menu. In this menu, they would be able to return to the home screen. I have tried to use .addKeyListener() as you will see below. I ...
0
votes
1
answer
154
views
How to open new window by clicking label in java?
I want to open a new window when I click the label. By implementing a key pressed listener. But it is not working. Even nothing is happening.
JLabel lblNewLabel_2 = new JLabel("Create New Account!...
1
vote
1
answer
86
views
Is there an event listener in the Zelle graphics module?
Is there an event listener when using graphics.py (Zelle) and Python?
With turtle graphics there is: onkeypress.
With pygame there is: if event.key == pygame.K_w:.
I am hoping to find something that ...
0
votes
1
answer
1k
views
Java TSM AdjustCapsLockLEDForKeyTransitionHandling
I am trying to capture up,down,right,left keys from KeyEvent, and I am getting following message when I press a key:
2021-06-05 00:46:11.176 java[47646:1823153] TSM ...
1
vote
1
answer
95
views
React JS keyDown Listener glitching
In my code I have:
useEffect(() => {
window.addEventListener("keydown", handleKeyDown);
});
This creates an event listener to listen to my keyboard. Then on my handleKeyDown I ...
0
votes
1
answer
19
views
KeyPressed method doesn't update when player turns (rotates)
I'm wondering how to make it so the head of the ship (the player) updates the direction that the ship is going. Currently it works like this:
The player holds the up/down arrow key and the right/left ...
1
vote
0
answers
54
views
Iterating through a list using a key listener (pynput) without copying words manually
Description of what I want to achieve:
I have a file which consists of words. Let's say they are "fish","tacos","burger".
Every time I paste a word (cmd + v on Mac or ...
0
votes
0
answers
254
views
Making Doodle Jump Using Java: How to get Doodle to jump
I am creating a doodle jump game and I am very confused. I have to make the doodle jump but I am so lost. I have put the keys (space, A, D) into the KeyListener and I am not sure why it's not working. ...