• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Listening keyboard and mouse events in the background

 
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I have a dictionary program. It will run continuously in the background.
When the user clicks ctrl+rightMouseButton, it will select the word at the focus, and send it to the dictionary module.
In order to do that, I think I have to use several threads:
1- For the application waiting in the background
2- Listening for the keyboard events in general
3- Listening for the mouse events in general
4- Listening for the focusing events
5- Listening for the clipboard events (already running)

There will be at least 2 hotKeys: one for program activation, and one for the word selection.
When word selection key activated, I will send a double-click to the component at the focus in order to select the word at the focus, and then send a ctrl-c to copy the selected word to the clipboard.
How should I run those threads altogether?
While listening for the clipboard, there is a sleep(100) method. What does happen during that period? Does waiting affect only that thread, or the whole application? Will it affect the general performance of the application?
As you can see easily, I know very little about threads.
What can I do? What should I do?
Especially I need some simple samples.
Thanks in advance.
Ahmet Aksoy
 
Ranch Hand
Posts: 1170
Hibernate Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
wait only affects the thread that makes the call. I doubt if you need threading for your application though. How do you plan to interact with the target applicaiton? Are you planning on a totally seperate running program that will interact through the OS with the target application? If so you will probably be doing lots of JNI.
 
Rancher
Posts: 5008
38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I don't think you need your own threads for listeners on the keyboard/mouse events. The AWT engine(part of the JVM) normally handles that. Your code needs to add listeners for each of the type events you want to handle.
When your listener is called with an event, it can then start a thread to do the work necessary, freeing the AWT engine's thread.

?will select the word at the focus
Where are the words that are at the focus? Do you mean at the caret?
Focus is at a component level and a component such as a TextArea can contain many words.
 
Ahmet Aksoy
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Mr. C Lamont Gilbert,
Here are my expectations: (now I'm talking about only the windows system)
My program will be waiting on the system tray until the user hits ctrl-right click. By using a focusListener, I hope to know the object which had focus when the mouse clicked, and the key pressed. After then I will send a double-click from my thread. Since there will be no visual part of the thread, there will be no change in the focus, and double clicking will make the word to be selected which was shown by the cursor. After then the thread will send a Ctrl-C in order to copy the selected word to the system clipboard.
When user presses ctrl-right-click, my thread will capture it, and change to a double-click, and then a ctrl-C.
My application can now listen to the clipboard events, and capture the copied text into it automatically. So, I will obtain the word which was under the cursor.
I don't know yet whether I can succeed that scenario or not?
I want to find some clues.
Ahmet Aksoy
 
Ahmet Aksoy
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Norm Radder,

I'm not sure whether I must use threads for such a solution, or not.
However, in order to capture the strings copied to the clipboard, I had used threads, and I thought that I could use them for a more complicated problem also.
First, I will try to make a small listener program. It will listen to the keyboard, and the mouse and it will printout the location and the related values of them.
If I can succeed it, then I will try to select the words under the cursor, using ctrl-right click.
At the last step, I will try to copy the selected word to the clipboard.

There is another solution for my problem: "Character Recognition" from the screen. But that will be a far more difficult solution

Ahmet Aksoy
 
Mr. C Lamont Gilbert
Ranch Hand
Posts: 1170
Hibernate Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
you probably dont need to send the double click. There is probably some other method of getting the word under the cursor. I know there are screen reading programs that are capable of doing it, and in USA OS makers are putting facilities into the OS in support of screen reading due to the Americans with Disabilities Act. So I would check the OS API to see what is available and check under accesibility.
 
Ahmet Aksoy
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You might be right!
I found some small clues for c# at http://www.codeproject.com/csharp/kbdListenerPackage.asp
I'll try to check WinAPI also.
Thanks.
Ahmet Aksoy
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic