Solved

String or char to KeyEvent ??

Posted on 2006-11-08
5
1,193 Views
Last Modified: 2008-02-01
Is there already a method that will convert a String or a char to a keystroke.

For example If I have the word "Hamburg" I could call a method String.toKeyEvent("Hamburg"), that would convert this to keystrokes.

At the moment I have written a large switch statement which containes all of the alphabet, but I was wondering whether there was a better method.

Thanks

0
Comment
Question by:mr_mooray
  • 2
5 Comments
 
LVL 6

Accepted Solution

by:
_iskywalker_ earned 250 total points
ID: 17896700
You could use a hash method!
in perl for example you could open an array with:
mykeys{"HamBURG"}='k';
so
print mykeys{"HamBURG"}."\n";
will print
k
you can use also a function for it but i think java have it, which language you are using?
another way  to do this is making  2 dimension arrays:
mykeys[][]=
{{"k","HAMBURG"}};
so you must search through the second dimension for optaining the first.
A hash is surely in all common langugaes implementated search for it, it is the easist way.
0
 

Author Comment

by:mr_mooray
ID: 17896744
Im using java, sorry not to mention.

At the moment I have a large switch statement:

public void typeLetter(char c) {
            try {
                  Robot robot = new Robot();
                  robot.delay(10);
                  
                  switch (c) {
                  case 'a':
                        robot.keyPress(KeyEvent.VK_A);
                        robot.keyRelease(KeyEvent.VK_A);
                        break;
                  case 'b':
                        robot.keyPress(KeyEvent.VK_B);
                        robot.keyRelease(KeyEvent.VK_B);
                        break;
                  case 'c':
                        robot.keyPress(KeyEvent.VK_C);
                        robot.keyRelease(KeyEvent.VK_C);
                        break;
                  case 'd':
                        robot.keyPress(KeyEvent.VK_D);
                        robot.keyRelease(KeyEvent.VK_D);
                        break;
                  case 'e':
                        robot.keyPress(KeyEvent.VK_E);
                        robot.keyRelease(KeyEvent.VK_E);
                        break;
                  case 'f':
                        robot.keyPress(KeyEvent.VK_F);
                        robot.keyRelease(KeyEvent.VK_F);
                        break;

...

Im not sure what you mean by hashing or how I could this.
0
 
LVL 6

Expert Comment

by:_iskywalker_
ID: 17896889
here some tutorial, the point is they will be faster than every time making a switch (i hope they are faster, since a switch is already pretty primitive ).

http://www.particle.kth.se/~lindsey/JavaCourse/Book/Part1/Java/Chapter10/hashtable.html
http://www.roseindia.net/javatutorials/javahashmap.shtml

search in google hashmap tutorials, there is a lot.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
wordcount challenge 11 111
Image decoding from Camera 3 73
Adoquery sql  left join does not work 25 81
how to use laptop or pad camera in vb.net windows application 2 55
Entering a date in Microsoft Access can be tricky. A typo can cause month and day to be shuffled, entering the day only causes an error, as does entering, say, day 31 in June. This article shows how an inputmask supported by code can help the user a…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

25 Experts available now in Live!

Get 1:1 Help Now