|
|||||||
|
|
|
![]() |
|
|
Strumenti |
|
|
#1 |
|
Senior Member
Iscritto dal: Mar 2008
Messaggi: 401
|
[Java] Simulare la pressione di un tasto
E' possibile in java simulare la pressione di un tasto (tastiera e/o mouse)?
Come? Grazie per l'aiuto. |
|
|
|
|
|
#2 |
|
Senior Member
Iscritto dal: Jan 2004
Città: ROMA
Messaggi: 2055
|
Ciao,
per quanto riguarda la tastiera, so che si può fare con KeyEvent. A rigor di logica (ma quì non sono sicuro), dovresti poter emulare anche un evento del mouse utilizzando MouseEvent. |
|
|
|
|
|
#3 |
|
Senior Member
Iscritto dal: Aug 2005
Città: Roma sud
Messaggi: 590
|
Preso da qui:http://www.java-tips.org/java-se-tip...y-presses.html
Codice:
try {
Robot robot = new Robot();
// Simulate a mouse click
robot.mousePress(InputEvent.BUTTON1_MASK);
robot.mouseRelease(InputEvent.BUTTON1_MASK);
// Simulate a key press
robot.keyPress(KeyEvent.VK_A);
robot.keyRelease(KeyEvent.VK_A);
} catch (AWTException e) {
e.printStackTrace();
}
__________________
-Mac Book intel core duo 1,83GHz, 1,25 Gb RAM -Amd athlon 64 dual core 4400+, 2 GB RAM, Asus a8n-sli Deluxe, totale 500 GB di HARD DISK(4 hdd) |
|
|
|
|
|
#4 |
|
Senior Member
Iscritto dal: Mar 2008
Messaggi: 401
|
Thanks thanks thanks thanks!!!!!
Grazie 1000 a tutti. Edit: Solo una cosa: il metodo r.mousePress(int) vuole in input un intero che rappresenta il pulsante da premere; ho cercato nella classe MouseEvent, ma non ho trovato risposta. 0 vale per il tasto sx, 1 per il centrale, e 2 per il dx? Oppure no? E poi il metodo r.mouseWheel(int) serve per far "scrollare" la rotellina del mouse, vero? Illuminatemi please. Ultima modifica di agente mm8 : 09-11-2008 alle 16:49. |
|
|
|
|
|
#5 |
|
Senior Member
Iscritto dal: Aug 2005
Città: Roma sud
Messaggi: 590
|
No...non bisogna passargli un intero ma come c'e' scritto InputEvent.BUTTON1_MASK
dai un occhiata qui... Codice:
Q: More about Robot! I met with a problem in using class Robot.mousePress... The compiling process is successful. But when I run it, I receive "IllegalArgumentException: Invalid combination of button flags". I don t quit understand this information. Part of my code is as following: Robot rMouse=new Robot(); int button=1; rMouse.mousePress(button); rMouse.mouseRelease(button); I am really confused. Will you please give me some advice? Thank you in advance! Answer: You are not using a valid value for the argument to the mousePress() and mouseRelease() methods. If you check the API documentation, you ll find the valid values are a combination of one or more of the following constants: InputEvent.BUTTON1_MASK InputEvent.BUTTON2_MASK InputEvent.BUTTON3_MASK plus others which represent the Ctrl, Alt, and Shift keys. To press the left mouse button, you want to use: rMouse.mousePress(InputEvent.BUTTON1_MASK); Edit: qui c'e' un esempio molto esplicativo http://www.java2s.com/Code/JavaAPI/j...leftbutton.htm P.S. Si MouseWheel e' per far scrollare la rotellina... leggi qui http://jfcunit.sourceforge.net/api/j...,%20int,%20int)
__________________
-Mac Book intel core duo 1,83GHz, 1,25 Gb RAM -Amd athlon 64 dual core 4400+, 2 GB RAM, Asus a8n-sli Deluxe, totale 500 GB di HARD DISK(4 hdd) Ultima modifica di frizzo28 : 09-11-2008 alle 17:39. |
|
|
|
|
|
#6 |
|
Senior Member
Iscritto dal: Mar 2008
Messaggi: 401
|
Ok, grazie 1000.
|
|
|
|
|
|
#7 | |
|
Senior Member
Iscritto dal: Oct 2007
Città: Padova
Messaggi: 4131
|
Quote:
Il fatto che poi BUTTON1_MASK sia definito come un intero statico nella classe InputEvent è una questione di coerenza e chiarezza, ma resta pur sempre un intero
__________________
As long as you are basically literate in programming, you should be able to express any logical relationship you understand. If you don’t understand a logical relationship, you can use the attempt to program it as a means to learn about it. (Chris Crawford) |
|
|
|
|
|
|
#8 | |
|
Senior Member
Iscritto dal: Aug 2005
Città: Roma sud
Messaggi: 590
|
Quote:
__________________
-Mac Book intel core duo 1,83GHz, 1,25 Gb RAM -Amd athlon 64 dual core 4400+, 2 GB RAM, Asus a8n-sli Deluxe, totale 500 GB di HARD DISK(4 hdd) |
|
|
|
|
|
| Strumenti | |
|
|
Tutti gli orari sono GMT +1. Ora sono le: 00:10.





















