Generate Key Events without pressing key???
Hi,
Is it possible to generate key events without pressing a key in swing???
i dont know if the question is logical or not, but just i want to generate some display as if the key is pressed by the user
Ashish
assuming c represents a text field.
This will type the character 'a' in the text field:
c.dispatchEvent( new KeyEvent (c, KeyEvent.KEY_TYPED, 0, 0, KeyEvent.VK_UNDEFINED, 'a') );
This will invoke Ctrl+F1, which will show the tool tip for the text field:
c.dispatchEvent( new KeyEvent (c, KeyEvent.KEY_PRESSED, 0, KeyEvent.CTRL_MASK, KeyEvent.VK_F1) );
Similar Messages
-
Getting key events without a jcomponent...
Is it possible to get key events without adding a keylistener to a jpanel? I want a class of mine to manage input of it's own, but it has no reference to a jpanel. They don't necessarily have to be KeyEvents, but just some way to detect if a key has been pressed (like the arrow keys). How can I do this? Thanks.
Lots of components can listen for key events.
What does your class subclass?It doesn't subclass anything. I am creating a custom menu system for my game using images I have made for the tileset. I would like it to handle some keyboard events of its own. (Like if the down arrow is pressed, it will move the focus down to the next component on its own). Right now I am currently passing the key events from my fullscreen jpanel to the menu class and it is handling them that way. Thanks. -
How to trigger 'save' event without pressing SAVE button
Hi, i want to execute my 'save' event without press the SAVE button.
I want to simulate press the button with abap code and sy-ucomm = 'SAVE'.
Is there a function module for this functionality
Thanks
Reward PointsWell, than just forget about the buttons and create some code at the end of the PAI event which you have already coded (i realize some actions ( with my code)). Just do a perform event_xxx and perform event_yyy. The code which will be executed (processed) will look exactly the same as if you had created it when pushing buttons:
CASE OK_CODE.
WHEN 'AAA'.
let's say this is done with your code
perform event_aaa.
perform: event_xxx, event_yyy.
WHEN 'XXX'.
perform event_xxx.
WHEN'YYY'.
perform event_yyy.
ENDCASE.
Helpful? -
RemoteApp receives multiple KeyUp events without any keys being pressed
Hi All,
I have a very simple winforms app that I am using to try and track down what is happening with keyboard events when using RemoteApp.
Basically I have a form and a textbox that track the KeyDown, KeyPress and KeyUp events.
As soon as I start my app via RemoteApp I receive multiple KeyUp events without even pressing a key.
Does anyone know why RemoteApp would be sending these random KeyUp events.
The code of my simple test app is as follows:
Public Class Form1
Dim lst As New List(Of String)
Private Sub AddtoList(str As String)
lst.Add(str)
End Sub
Private Sub TextBox1_KeyDown(sender As Object, e As System.Windows.Forms.KeyEventArgs) Handles TextBox1.KeyDown
AddtoList("txt KeyDown" & vbTab & "KeyCode is " & e.KeyCode)
End Sub
Private Sub TextBox1_KeyPress(sender As Object, e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress
AddtoList("txt KeyPress" & vbTab & "KeyChar is " & e.KeyChar)
End Sub
Private Sub TextBox1_KeyUp(sender As Object, e As System.Windows.Forms.KeyEventArgs) Handles TextBox1.KeyUp
AddtoList("txt KeyUp" & vbTab & "KeyCode is " & e.KeyCode)
End Sub
Private Sub Form1_FormClosing(sender As Object, e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
AddtoList("Form Closing")
IO.File.AppendAllLines(Application.StartupPath & "\SimpleKeyUp_v2.txt", lst)
End Sub
Private Sub Form1_KeyDown(sender As Object, e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown
AddtoList("Form KeyDown" & vbTab & "KeyCode is " & e.KeyCode)
End Sub
Private Sub Form1_KeyPress(sender As Object, e As System.Windows.Forms.KeyPressEventArgs) Handles Me.KeyPress
AddtoList("Form KeyPress" & vbTab & "KeyChar is " & e.KeyChar)
End Sub
Private Sub Form1_KeyUp(sender As Object, e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyUp
AddtoList("Form KeyUp" & vbTab & "KeyCode is " & e.KeyCode)
End Sub
Private Sub Form1_Load(sender As Object, e As System.EventArgs) Handles Me.Load
AddtoList("Form Load")
End Sub
End Class
Simply opening and closing the app via RemoteApp gives the following results:
Form Load
Form KeyUp KeyCode is 9
txt KeyUp KeyCode is 9
Form KeyUp KeyCode is 16
txt KeyUp KeyCode is 16
Form KeyUp KeyCode is 16
txt KeyUp KeyCode is 16
Form KeyUp KeyCode is 17
txt KeyUp KeyCode is 17
Form KeyUp KeyCode is 17
txt KeyUp KeyCode is 17
Form KeyUp KeyCode is 9
txt KeyUp KeyCode is 9
Form KeyUp KeyCode is 18
txt KeyUp KeyCode is 18
Form KeyUp KeyCode is 9
txt KeyUp KeyCode is 9
Form KeyUp KeyCode is 18
txt KeyUp KeyCode is 18
Form KeyUp KeyCode is 9
txt KeyUp KeyCode is 9
Form Closing
Cheers and Thanks in Advance!
DwayneHi,
It seems that your issue has been out of the scope of this forum.For coding issue,I suggest you ask in the
MSDN forum to see whether anyone can help you out.
Regards,
Clarence
TechNet Subscriber Support
If you are
TechNet Subscription user and have any feedback on our support quality, please send your feedback
here.
Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread. -
Send a press key event without Batch Input?
Hi.
I need send a auto press key event (by example: press F8), by code.
When I put a instruction in the report, the report simulate the key pressed.
Exist some FM to do it? Is it posible?
Thanks!Hi Marcos,
you can use the method I recommended in an additional timer object method .
Please adapt the below sample program I used to display the current time with auto update:
*& Report ZZCLOCK
*& may be used to keep connection
REPORT zzclock.
* CLASS lcl_gui_timer DEFINITION
class lcl_gui_timer definition inheriting from cl_gui_control.
PUBLIC SECTION.
CONSTANTS: eventid_finished TYPE i VALUE 1 .
CLASS-DATA: interval TYPE i VALUE '0'.
EVENTS: finished .
METHODS:
cancel
EXCEPTIONS
error,
constructor
IMPORTING
lifetime TYPE i OPTIONAL
value(shellstyle) TYPE i OPTIONAL
value(parent) TYPE REF TO cl_gui_container OPTIONAL
EXCEPTIONS
error,
run
EXCEPTIONS
error,
dispatch REDEFINITION.
ENDCLASS. "lcl_gui_timer DEFINITION
* CLASS lcl_event_handler DEFINITION
CLASS lcl_event_handler DEFINITION.
PUBLIC SECTION.
CLASS-METHODS:
on_finished
FOR EVENT finished OF lcl_gui_timer.
ENDCLASS. "lcl_event_handler DEFINITION
DATA: gui_timer TYPE REF TO lcl_gui_timer.
DATA: event_handler TYPE REF TO lcl_event_handler.
DATA: timeout_interval TYPE i VALUE '9'.
PARAMETERS:
p_datum TYPE sy-datum,
p_uzeit TYPE sy-uzeit.
AT SELECTION-SCREEN OUTPUT.
* set to time rounded to 10 seconds
p_datum = sy-datum.
p_uzeit = sy-uzeit.
CREATE OBJECT gui_timer.
SET HANDLER event_handler->on_finished FOR gui_timer.
gui_timer->interval = timeout_interval.
CALL METHOD gui_timer->run.
* CLASS lcl_event_handler IMPLEMENTATION
CLASS lcl_event_handler IMPLEMENTATION.
METHOD on_finished.
* Start Timer again
gui_timer->interval = timeout_interval.
CALL METHOD gui_timer->run.
* cause PAI
CALL METHOD cl_gui_cfw=>set_new_ok_code
EXPORTING
new_code = 'REFR'.
ENDMETHOD. "on_finished
ENDCLASS. "lcl_event_handler IMPLEMENTATION
* CLASS lcl_gui_timer IMPLEMENTATION
CLASS lcl_gui_timer IMPLEMENTATION.
METHOD constructor.
TYPE-POOLS: sfes.
DATA clsid(80).
DATA event_tab TYPE cntl_simple_events.
DATA event_tab_line TYPE cntl_simple_event.
IF clsid IS INITIAL.
DATA: return,
guitype TYPE i.
guitype = 0.
CALL FUNCTION 'GUI_HAS_OBJECTS'
EXPORTING
object_model = sfes_obj_activex
IMPORTING
return = return
EXCEPTIONS
OTHERS = 1.
IF sy-subrc NE 0.
RAISE error.
ENDIF.
IF return = 'X'.
guitype = 1.
ENDIF.
IF guitype = 0.
CALL FUNCTION 'GUI_HAS_OBJECTS'
EXPORTING
object_model = sfes_obj_javabeans
IMPORTING
return = return
EXCEPTIONS
OTHERS = 1.
IF sy-subrc NE 0.
RAISE error.
ENDIF.
IF return = 'X'.
guitype = 2.
ENDIF.
ENDIF.
CASE guitype.
WHEN 1.
clsid = 'Sapgui.InfoCtrl.1'.
WHEN 2.
clsid = 'com.sap.components.controls.sapImage.SapImage'.
ENDCASE.
ENDIF.
CALL METHOD super->constructor
EXPORTING
clsid = clsid
shellstyle = 0
parent = cl_gui_container=>default_screen
autoalign = space
EXCEPTIONS
OTHERS = 1.
IF sy-subrc NE 0.
RAISE error.
ENDIF.
CALL METHOD cl_gui_cfw=>subscribe
EXPORTING
shellid = h_control-shellid
ref = me
EXCEPTIONS
OTHERS = 1.
IF sy-subrc NE 0.
RAISE error.
ENDIF.
* Register the events
event_tab_line-eventid = lcl_gui_timer=>eventid_finished.
APPEND event_tab_line TO event_tab.
CALL METHOD set_registered_events
EXPORTING
events = event_tab.
ENDMETHOD. "constructor
METHOD cancel.
CALL METHOD call_method
EXPORTING
method = 'SetTimer'
p_count = 1
p1 = -1
queue_only = 'X'
EXCEPTIONS
OTHERS = 1.
IF sy-subrc NE 0.
RAISE error.
ENDIF.
ENDMETHOD. "cancel
METHOD run.
CALL METHOD call_method
EXPORTING
method = 'SetTimer'
p_count = 1
p1 = interval
queue_only = 'X'
EXCEPTIONS
OTHERS = 1.
IF sy-subrc NE 0.
RAISE error.
ENDIF.
ENDMETHOD. "run
METHOD dispatch .
CASE eventid.
WHEN eventid_finished.
RAISE EVENT finished.
ENDCASE.
ENDMETHOD. "dispatch
ENDCLASS. "lcl_gui_timer IMPLEMENTATION
Hope that's what you are looking for. I got the idea from a project where they used it to auto refresh an ALV grid...
You may also search this forum for keywords timer or autorefresh. It has been discussed here earlier.
Regards,
Clemens -
No key event when compose keys are pressed
I am supporting a legacy application for Sabre which maps some of the keys differently. For example, on a French keyboard the Compose key which is used to put a ^ on top of the vowel characters is to be remapped to produce a special character called a "Change Character" that has a special use for reservation agents that use Sabre
The problem is, the first time you press the ^ compose key there is no key event apparently because the VM figures it doesn't yet know what key to report, it is expecting you to press a character such as 'o' and then you get an 'o' with a '^' on top of it.
If you press the ^ compose key a second time, you get the following key events:
keyPressed
keyTyped
keyTyped
keyReleased
On the screen you will see two ^ characters appear. Currently I remap the ^ character to the "Change Character", and I suppress the second keyTyped event so that I only get one character. The problem is that the user ends up having to press the key twice to get one "Change Character."
I have no fix for this problem because there is no key event produced when they press the ^ compose key the first time.
By the way, this behavior appears to have been introduced with jdk 1.3. The older jdk did produce a key event the first time you pressed the compose key. I would expect that this behavior was considered to be a bug and was fixed in jdk 1.3.
Is there some other way to detect when the user presses a compose key? If not, is it possible for future jdk releases to report a keyPressed event when a compose key is pressed? This event would not cause a character to appear on the screen, but would allow programs to detect when the compose key is pressed.
There is already a key on the French keyboard that behaves this way. It is the key to the left of the '1' key and it has the pipe symbol on it. If you press Shift plus this pipe key, no character is produces but a keyPressed event with a keycode of 222 is produced. I merely point this out to show that there is a way to report key events whithout producing output on the screen.
Thanks, Brian BrudererI don't know if this actually helps, but it seems that you can bind an Action to a dead key like the circumflex of the French keyboard
Keymap keymap = textPane.addKeymap("MyEmacsBindings", textPane.getKeymap());
Action action = getActionByName(DefaultEditorKit.beginAction );
KeyStroke key = KeyStroke.getKeyStroke(KeyEvent.VK_DEAD_CIRCUMFLEX);
keymap.addActionForKeyStroke(key, action);I saw this on a Swing tutorial and modified it slightly. Have a look at it :
http://java.sun.com/docs/books/tutorial/uiswing/components/generaltext.html
Chris -
How to listen a key event without having any window component
Hi all,
I would like to know how can I listen key events from an application that doesn't use windows
Thanksyoiu can make a Thread run inside your application. This will listen for inputs in the command line. For examplethis is part of a chat server (on the console) with let the server manager to enter messages or commands.
The message or command entered on the console by the user is catched and processed as a String. The string is passed to the processConsole() method, you must define yourself.
Th Thread is never stopped, so the user may enter any message at any time
The core of you application should also be a Thread for better performance, but maybe it will also work without. Jst try and provide needed importstatements.
Runnable runInput = new Runnable() {
public void run() {
while(true) {
try {
byte buffer[] = new byte[255];
System.out.print(prompt);
System.in.read(buffer);//, 0, 255);
String inputString = new String(buffer, "Default");
processConsole(inputString);
catch(NullPointerException npe) {
System.out.println("Syntax error");
catch(Exception e) {e.printStackTrace(); }
Thread inputThread = new Thread(runInput);
inputThread.start(); -
Difference between opening PDF within IE with pressing SHIFT key and without SHIFT key
Hi,
I want to know when we open a PDF file within Internet Explorer it is using ActiveX control AcroPDF.dll behind the scene.
Now If I open PDF within IE with keep pressing SHIFT key the behavior is different then without pressing SHIFT key?
Is AcroPDF.dll behaves differently in this situation?
Thanks,
TwinkleI've saved two files on my desktop:
f1040.pdf - downloaded from www.irs.gov - 187 KB
afmod07.2.1g.pdf - downloaded from my intranet - 1,04MB
I've powered off my PC and restarted for each file. I've opened files with double-click on them. I've encountered the same problem, when double-clicked on files in task manager two Acrord32.exe appeared, the PC was doing anything for about 10 second, after that I've encountered no activity in task manager (numbers not vary) for other 10 seconds (like freeze) and after that other about 10 seconds of loading. So after about 30 seconds the file opens with stand-alone Acrobat Reader (11.0.10).
If I retry now (after the first slow startup "of the day") the file opens in 2-3 seconds.
So:
- first open of the day or rebooting PC: 30-45 seconds
- second open of the file: 2-3 seconds
This is happening only with PDFs with forms.
Yuri -
Hi,
Could you tell me how to get F1 key event which is
nothing to do with any control's focuses?
For example, suppose there's a button saying "F1 exit",
and the focus is on some other button.
In such case, if user pushes F1, program should exits.
That's what I want to do.
Thank you.For example:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class Example {
public static void main(String[] args) {
JPanel p = new JPanel();
p.add(new JButton("sample button"));
Action action = new AbstractAction("homer") {
public void actionPerformed(ActionEvent evt) {
System.out.println("DOH!");
KeyStroke stroke = KeyStroke.getKeyStroke("F1");
Object key = action.getValue(Action.NAME); //homer
p.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(stroke, key);
p.getActionMap().put(key, action);
JFrame f = new JFrame("Example");
f.setContentPane(p);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.pack();
f.setLocationRelativeTo(null);
f.setVisible(true);
} -
Key events & Combinations of keys
Hi,
I'm listening to key events and it's fine one one key is pressed;
if (event.getKeyCode() == KeyEvent.VK_UP)
}But I need to know when a combination of keys is pressed (like ctrl-a). How can I know if two specifics keys are pressed together?
Thank you...Read JavaDoc. java.awt.event.InputEvent class.
if (event.getKeyCode() == KeyEvent.VK_UP && event.isControlDown())
} -
Windows Intunes software inventory with product keys or without product keys
Its sounds good to manage and work faster but it would also save more time If Windows intune can also retrieve the product key information from all the clients machines. So my question is can windows intune retrieve the product keys of any programs installed.
or only few if any??There's no standard way to store product keys though so there's no way for a management tool like Intune to know how to retrieve them. If you can first get all software vendors to store their product keys, in a readable format, in a common way and place,
then this would be easy. Until then though, Intune is not magic and can not figure out where the thousands of software vendors are storing their keys let alone be able to unencrypt/unencode them if they are stored using some secure format.
Jason | http://blog.configmgrftw.com -
Handling Enter key event in JTable
Hi...
This is particularly for the user "VIRAVAN"...
I have followed your method ,and got results too.. but the
processKeyBinding(.. method is called 4 times,same problem addressed by you before, but I didn't understood it...
Please help me...
Here is my code...
protected boolean processKeyBinding(KeyStroke ks, KeyEvent e,int condition, boolean pressed)
System.out.println("Wait");
if (ks == KeyStroke.getKeyStroke(KeyEvent.VK_ENTER,0))
int selRow = getSelectedRow();
int rowCount = getRowCount();
int selCol = getSelectedColumn();
String val =(String)getValueAt(selRow,selCol);
boolean b= getCellEditor(selRow,selCol).stopCellEditing();
System.out.println(b);
System.out.println(rowCount-1 + " "+ selRow + " " + getSelectedColumn());
if((!val.equals("")) && selRow==rowCount-1)
System.out.println(rowCount-1 + " "+ getSelectedRow()+ " " + getSelectedColumn());
blank1 = new String[columns];
for(int p=0;p<columns;p++)
blank1[p]="";
Diary.this.datarows.addElement(blank1);
// dataModel.fireTableStructureChanged();
//dataModel.fireTableDataChanged();
Diary.this.dataModel.fireTableChanged(null);
else if(ks ==KeyStroke.getKeyStroke(KeyEvent.VK_1,0))
System.out.println("One One One One ");
return super.processKeyBinding(ks,e,condition,pressed);It's been a while since I looked at the code, but essentially there are three key event types:
1) key pressed,
2) key typed,
3) key released.
So I would expect the processKeyBind to see all three of them. However, ks==KeyStroke.getKeyStroke(KeyEvent.VK_ENTER,0) is true only when a key typed event is detected (the other types can be ignored by passing it up the food chain where they will eventually be consumed). Now...., if I understand you correctly, you want to terminate edit on the present of Enter key, right? Here is how I'd suggest you do:
protected boolean processKeyBinding(KeyStroke ks, KeyEvent e, int condition, boolean pressed) {
if (isEditing()) {
Component editorComponent=getEditorComponent();
editorComponent.stopCellEditing();
return true;
return super.processKeyBinding(ks,e,condition,pressed);
}Ok.... now, it appears that you want to do something else also... i.e., add a new row to the table if the editing row is the last row and the editing column is the last column of the last row. You can't do that in the same thread (i.e., you must wait until the update in the current thread is completed). So, what you must do is use the SwingUtilities.InvokeLater, like this:
protected boolean processKeyBinding(KeyStroke ks, KeyEvent e, int condition, boolean pressed) {
if (isEditing()) {
Component editorComponent=getEditorComponent();
editorComponent.stopCellEditing();
if (getEditingRow()+1==getRowCount() && getEditingColumn()+1==getColumnCount()) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
// put the code for adding new row here
return true;
return super.processKeyBinding(ks,e,condition,pressed);
}OK?
;o)
V.V.
PS: posted code is untest but should work! -
What is the best approach to handling key events (listening for keys being pressed)?
Are there any widgets out there for this purpose? Just do it in JavaScript?
ThanksThe best 'approach' for key events in Captivate e-learning courses is to avoid them as much as possible. They are a can of worms because every browser is different in terms of which keystrokes it will allow you to use. So you may find that you can use certain keystrokes in one browser but only some of them will work in another.
Widgets are not the answer because they are ActionScript and AS calls are close to the bottom of the pile. JavaScript will also only get you so far because even that happens AFTER the browser gets first pick. -
How to generate key events to a componet without keyboard
I want to generate a key event, a Keylistener is already there, (in fact, java3D's KeyNavigatorBehavior). I want to use other input methods instead of key pressings, so how I generate the key event manually
thx,Look at java.awt.Robot. It has a keyPress() method to simulate key presses.
-
Lag on key press (key event)
Hello, I am currently working on a simple game in Java. I've used Java's Key_Pressed in Key Event to control a ship moving back and forth with the up and down keys. I've noticed that when a key is pressed there is a short pause before the ship actually moves. What can I do to avoid this pause?
The "repeat rate" for holding a key down is controlled by the OS.
You should not be relying on multiple KeyEvents to move your component as the repeat rate will vary from machine to machine. Actually you should not be using KeyEvents anyway you should be using [url http://java.sun.com/docs/books/tutorial/uiswing/misc/keybinding.html]Key Bindings
On keyPressed binding you would start a Timer and then on keyReleased you stop the Timer. You can then control the interval at which the Timer fires so you game will be consistent on all machines.
Maybe you are looking for
-
Hello, in my lab i have 3 sites each with 3 VRF's configured. A diagram ist attached. I like to configure fixed bandwidth for each vrf. the central vrf should have 768 kbps and the the other ones ones should have 256 kbps each. What are the options i
-
How do i get rid of an error dj_sf_software?
How do i get rid of an error dj_sf_software keeps telling me its on a network resource thats unavailable? Ive uninstalled and re-installed to no avail. I had a previous all in one printer set-up which I uninstalled before installing my deskjet d 1420
-
Using flash shared object to have a load animation play only once
Hey all I have a swf on multiple pages, I onyl want it to play the load animation once, so I thought I would try the shared object to do this. //On frame 1 on my mc if it hasnt played the file below it should to gotoAndPlay frame 1 of my mc, logo_mc
-
Editing Red Footage in premiere help
Hi, Finally, I decided to edit red footage in Premiere cs6 this is my first edit can any one plz help how to Edit red footage,i mean red is a raw footage,am i first grade(basic color correction) the footages or edit the footage (my confusion) and
-
Problem in configuring IP address in desktop PC RT target
Hi, I am using Industrial PC (IMB Q670 R21) as my RT target.It has two ethernet ports out of which one is compatibe with LabVIEW RT. I have created USB Utility drive with LabVIEW 2012 and formated HDD. The PC boots into safe mode but the IP settings