Key Press Events
Hi there,
Im relatively new to java and need to implement a program which listens for a key press e.g. say the letter "n" and then performs an action, Is there a simple way to do this?
I've found some stuff on the web about the KeyListener class but i don't understand it very well.
Im wanting a solution which does this in the simplest way possible, any help you can give me would be greatly appreciated.
Cheers
yeh thats probly a good idea lol basically:
I have this system using a virtual reality suite at my university, on the 3 large screens in the suite i have some background images of different environments. The backgrounds are displayed using media player classic, one media player for each screen, left, mid and right. I have a web page which is connected to the media players which when refreshed changes to the next item in the playlist (in the media players) so all 3 players "change scene" at the same time.
Now my java program currently sends a refresh to this web page which in turn changes the background on the 3 screens. at the same time the program uploads an image onto the backgrounds at given co-oardinates. What im wanting next and am struggling with is for the image to be uploaded and the backgrounds to change when i press a key an for this to be repeated everytime i press that same key.
This way i can cycle through all the different backgrounds with a simple keypress.
Similar Messages
-
Question about generate key press event to system. help plz.
I am wondering if it is possible to write a java program to generate key press event(not receiving)to the local system so all the other program in the system receive those key press event also. Thanks.
Hi,
:. I don't know what exactly you intend to accomplish. But, I have used the following code in order to simulate keys pressing inside a Java application.
/* - - - Simulates TAB (java.awt.Event)
EventQueue evtq = Toolkit.getDefaultToolkit().getSystemEventQueue();
evtq.postEvent( new KeyEvent(this, KeyEvent.KEY_PRESSED,
0, 0, KeyEvent.VK_TAB, KeyEvent.CHAR_UNDEFINED) );
evtq.postEvent( new KeyEvent(this, KeyEvent.KEY_RELEASED,
0, 0, KeyEvent.VK_TAB, KeyEvent.CHAR_UNDEFINED) );
/* - - - Simulates Shift+TAB (java.awt.Event)
evtq.postEvent( new KeyEvent(this, KeyEvent.KEY_PRESSED, 0,
InputEvent.SHIFT_DOWN_MASK, KeyEvent.VK_TAB,
KeyEvent.CHAR_UNDEFINED) );
evtq.postEvent( new KeyEvent(this, KeyEvent.KEY_RELEASED, 0,
InputEvent.SHIFT_DOWN_MASK, KeyEvent.VK_TAB,
KeyEvent.CHAR_UNDEFINED) );:. However, as far as I know to send keys to the whole OS you have to create a 'Hook' as described inside Win32API documentation. That's for Microsoft Windows naturaly.
Cheers.
Roque -
Unable to receive Tab key press event
Hello,
I have written a component which extends JComponent.
For that , when Tab key is pressed I need to process something.
I have overridden the function processKeyBinding in my class.
But I am not getting any event for tab key press. For all the other key press events, the function is being called.
I also tried to create a action and add it to the action map. But that is also not working.
Can anyone explain me why it is not working and give me the solution.
Thanks in advance,
Anupublic static void removeTabFromFocusTraverval(Component c) {
int id = KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS;
Set strokes = c.getFocusTraversalKeys(id);
Set newStrokes = new HashSet(strokes);
newStrokes.remove(KeyStroke.getKeyStroke("TAB"));
c.setFocusTraversalKeys(id, newStrokes);
} -
How to binding a key press event of "Esc" to "cancle" button
I create a class extended JComponent. Than I add a button named "cancle " to it.
Than I add the class's instance to a JDialog object.
I try to get the key press event through add a keyListener to the class instance, but no works.
I try to add a keymap and action map to the dialog 's getRootPane() also no works.
Who can tell me how can I do?Thats the way I did it:
// map escape key
ActionListener escapeActionListener = new ActionListener()
public void actionPerformed(ActionEvent e)
cancelPressed();
this.registerKeyboardAction( escapeActionListener,
KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0, false),
JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT ); -
Hello, any know how can I raise a key press event throw code. For example I want to simulate that the user has press the A Key. How can I do that throw code?
Thanks a lot !!Hi there,
Your question has been discussed previously in the forums. Sounds like you want to programmatically click a button in WPF.
Please check out this post
http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=1329603&SiteID=1
Thanks,
Jennifer -
How to detect space key pressed event
I am working on a japplet where it is needed to pause the applet on the occurrence of a space bar key pressed event can anybody help
thanks in advanceHave a look at the tutorial:
http://java.sun.com/docs/books/tutorial/uiswing/events/keylistener.html
http://java.sun.com/docs/books/tutorial/uiswing/misc/keybinding.html
-Puce -
How to handle form close event or escape key press event for user defined f
Experts,
Please let me know how to handle form close event or escape key press event for user defined form...
Thanks & Regards,
Pravin.Hi
You can catch the form close event like this
If ((pVal.FormType = 139 And (pVal.EventType = SAPbouiCOM.BoEventTypes.et_FORM_CLOSE)) And (pVal.Before_Action = True)) Then
Try
SBO_Application.SetStatusBarMessage(pVal.EventType.ToString())
Catch ex As Exception
SBO_Application.SetStatusBarMessage(ex.Message)
End Try
End If
Hope this helps
Regards
Arun -
Can we fire key press event programmatically????
hi there,
is it possible in java to fire a key press event (of the associated component) programmatically??? like we can fire action event of a button by saying
button.doClick();
thanks in advance.
anshuYou can do so by using awt.Robot.keyPress(), just don't forget to do awt.Robot.keyRelease() afterwards!
Note that it doesn't work for Applets unless you sign them, for security reasons (you don't want to go into a site and have the applet click ctrl+alt+del for you, right?)
Cheers!
Moti -
I need message to be displayed when certain key pressed. Why it's not working?
import java.awt.*;
import java.awt.event.*;
import javax.swing.event.*;
import javax.swing.JFrame;
import javax.swing.JPanel;
public class TestKey extends JPanel implements KeyListener {
public TestKey(){
addKeyListener(this);
public static void main(String arg[]){
JFrame frame = new JFrame();
frame.setTitle("Test my keybord, man!");
frame.setSize(300, 200);
frame.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
Container contentPane = frame.getContentPane();
contentPane.add(new TestKey());
frame.setVisible(true);
public void keyPressed(KeyEvent ke){
System.out.println("key pressed");
public void keyTyped(KeyEvent ke){
System.out.println("key typed");
public void keyReleased(KeyEvent ke){
System.out.println("key released");
}public TestKey(){
setFocusable(true);//<----------
addKeyListener(this);
} -
How to change a h:outputText value in the current form on key pressed event
Hello Suners,
Greetings! I'm developing my first JSF web application and i'm trying to figure a way out to change outputText value when key pressed on another inputText so that when the user is typing his name for example he can see the letters showing respectively in the outputText.
I managed to do it onchange but the user must focus out of the inputText to see his name in the outputText which is not right and the form must submit onchange event which is annoying.
<h:inputText value="#{login.username}" title="name" id="name" required="true" onchange="this.form.submit()" >
<f:validateLength maximum="10" minimum="1"/>
<f:validator validatorId="myValidator"/>
<f:valueChangeListener type="classes.MyListener"/>
</h:inputText>Is there any listener i can associate with the "onkeypress" attribute? Can anyone help me to do that with JSF?
King Regards,hi, with JSF 2 you got the ajax tag, just tried it and it works fine :)
<h:inputText id="myinput" value="#{back.name}">
<f:ajax execute="@this" event="keyup" render="outtext"/>
</h:inputText>
<h:outputText id="outtext" value="#{back.name}"/>or before JSF 2
<h:outputScript name="jsf.js" library="javax.faces" target="head"/>
<h:inputText id="myinput" value="#{back.name}" onkeyup="jsf.ajax.request(this, event, {render: 'outtext'}); return false;"/>
<h:outputText id="outtext" value="#{back.name}"/>The name property is a simple String in the bean.
Hope this helps
Edited by: hereps on Aug 21, 2010 7:18 AM -
I have been pouring through the TLF API docs looking for
events to handle key presses on a TextFlow and I am not finding
anything. I'm sure it's simple, can anyone give me a clue? I'm
looking to detect Ctrl+B, Ctrl+I, etc.. to trigger formatting.The events go to the DisplayObjectContainerController. You
will want to override the processKey event functions to add special
handling. Those are in the protected methods section and are
inherited from a base class. -
Capture key press events with ExtendScript?
Is it possible to do this? I can't find an example in the documentation or online anywhere. I'd really like to know when the user presses the arrow keys while viewing the slideshow in Bridge.
Thanks!Thanks for the example Paul. I can see how to listen to key down events on Windows and Dialogs that I create. Do you know of way to listen for global (app-wide) key down events? These are not defined:
app.addEventListener('keydown',...)
app.document.addEventListener('keydown',...)
I'm trying to add to the slideshow mode by having a little palette dialog with the context information shown that I need. The default caption box doesn't have what our artists want. If the palette window is in focus, I get the keydown event, but if they're using the arrow keys to flip through the slideshow, I can't capture those.
Thanks for the help. -
Hi You all,
I'm trying to make an automatic Tab Key Press after fill some data to oEditText , plz guide me how can i do that ?
I will appreciate your help.
Peter.
Edited by: PeterHoang on Oct 12, 2011 12:22 PMHi
You can use sendkeys method for this
SBO_APPLN.SendKeys("{TAB}")
Regards
Arun -
How can i call key press event for dynamically created texbox
Hi,
I create a one texbox using javascript .now i want to call onFocus event that textbox.How is itI develop grid application using javascript only.When they press add button dynamically add one row and each cell contain one textbox for enter new data.if they want to edit previous data when cursor goes to that textbox,all textvalue is selected format
-
Hi,
In Oracle Forms 6i / 9i / 10g is there any trigger that can be fired on every key that I press on the keyboard.
Case 1.
If the ascii key value does not satisfy the condition on the single key I press then the message pops up. If the ascii key value is satisfied then it should allow to press the next key.
Note I know the trigger that fires after entering the complete word in the txtitem.
But I want the trigger on a single character.
Thank You.
Anthony JIn Oracle Forms 6i / 9i / 10g is there any trigger that can be fired on every key that
I press on the keyboard.No.
Well, perhaps 6i client-server but it was a long time ago for me.
For web-based apps you can use a pjc
http://sheikyerbouti.developpez.com/forms-pjc-bean/pages/keystrokeinterceptor.htm
Maybe you are looking for
-
Satellite A105-S4211 can be launched at safe mode only
Hello, I am a newer, and need help! I have Toshiba Satellite A105-S4211 laptop. My kid used it for a year, and told me the Window XP operating system could not be normally launched up. I tested it. This laptop only can be started at safe mode. I used
-
Hi All, Is there any possibility to do the dimension building and data loading at the same time using same source file. I am using essbase 6.5. and my data source would be excel sheets. If possible please suggest me how the source file should look li
-
User submitted Credit Card Historical Transactions Management Report by mis
A user has submitted the 'Credit Card Historical Transactions Management Report' by mistake. They have noticed that as a result of this, the concurrent request appears to have deactivated all iExpense unused transactions up to and including the date
-
Java.sql.SQLException: ORA-01000: maximum open cursors exceeded
What is wrong when there is such an sql exception?
-
Legacy vocal does not appear in Garage Band 10.0.2
As a legacy user of Garage Band '11, I saved my favorite vocal settings as an instrument under 'Vocals'. However, this 'instrument' doesn't show up in the Legacy section of Garage Band 10.0.2. Any idea why that might be?