Solved

String or char to KeyEvent ??

Posted on 2006-11-08
5
1,186 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
Comment Utility
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
Comment Utility
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_
Comment Utility
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

RIA (Rich Internet Application) tools are interactive internet applications which have many of the characteristics of desktop applications. The RIA tools typically deliver output either by the way of a site-specific browser or via browser plug-in. T…
Displaying an arrayList in a listView using the default adapter is rarely the best solution. To get full control of your display data, and to be able to refresh it after editing, requires the use of a custom adapter.
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
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…

771 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

11 Experts available now in Live!

Get 1:1 Help Now