Cool idea I have - is it doable?

I have an application thats basically a JFrame with a JPanel as a startmenu and a JDesktopPane as the desktop. What I want to do is to make a visual keyboard, that I can pop up as a JInternalFrame in the JDesktopPane. They keyboard will contain just about all the keys that a normal keyboard would. However, since its in its own JInternalFrame, it would also contain a button that would work like this;

1. You click on the button

2. Click on any other JInternalFrame

3. All the keys that you press will be sent to the JInternalFrame as thought hey were coming from a keyboard.

Is this even possible?

[630 byte] By [alienchilda] at [2007-11-26 19:58:36]
# 1

> Is this even possible?

Maybe. You can use the java.awt.Robot to do key presses and such, so that aspect isn't a problem.

The problem is the focus. You'll have to make sure that your buttons don't take the focus, otherwise the key events will get sent to them. There's a WindowFocusListener I think that might make this possible in java 2 java applications. Trying to get java to send key presses to non-java apps is gonna be impossible probably

tjacobs01a at 2007-7-9 22:54:27 > top of Java-index,Desktop,Core GUI APIs...
# 2

You'll have to make sure that your buttons don't take the focus, otherwise the key events will get sent to them.

I don't think this should be an issue as you should be pumping events directly rather than generating them and handing off to the KeyboardFocusManager or whatever.

If you have a "KeyEventPump" class which has a reference to the JDesktopPane and contains an "AttachPump" which implements InternalFrameListener and Action (and from which the button is created), then when invoked that action can rifle through the JInternalFrames in the desktop and attach itself as a listener to all of them. When a JInternalFrame becomes selected (maybe it can do this via PropertyChangeListener on the desktop pane actually), it then knows where it wants to send events and can stop listening. From there on in, you can invoke your key pumping.

I would suspect that as for pumping events, wouldn't Component.dispatchEvent() do the job? Not tried it, but it seems a reasonable bet.

The thing I'm not clear on is why this is a cool idea and what purpose it serves, but I'm curious :o)

itchyscratchya at 2007-7-9 22:54:27 > top of Java-index,Desktop,Core GUI APIs...
# 3

Thanks, cool ideas here that is noted in my big pile of "make this!".

The idea is cool for two purposes;

My presentation. Where I work, I usually work with support, or webdesign. I remember loving java when I went to school a few years ago, but time has passed and I forgot alot of it. I've picked it up now - and still loving it I may add (why did I ever quit?) - and am making somewhat of a behemoth of an application.

Without going indepth, the application is a collection of utilities that we are in dire need for (at least us doing support). It is a rather small firm (25ish employees) but with thousands of computers running out software. I am the kind of person who often see solutions and get ideas everytime we encounter a problem, so I have kept a few of those solutions to myself, and am now making applications to tackle them.

In a year or less, I'm gonna drop the bomb at one of our longer meetings, with a scheduled 2-3 hour presentation. Back to yourt question; why is it cool? Well, I know that some of the coders here have been tackling this very same problem in the programming language they use, and it's been rather frustrating. At my presentation, while showing examples, I will pop up my virtual keyboard, and start typing test data into my utility applications on our 77" SmartBoard, like it was the most normal thing to do :p

The second purpose is that stores around the world are more and more getting these touch-screens sunken into the table, and are using simple GUI operations without the use of a keyboard. With a class like this, maybe I can use it in some other usefull application later.

alienchilda at 2007-7-9 22:54:27 > top of Java-index,Desktop,Core GUI APIs...
# 4

I will pop up my virtual keyboard, and start typing test data into my utility applications on our 77" SmartBoard, like it was the most normal thing to do

Is that like an interactive whiteboard sort of thing?

If you have a stylus then the really cool thing to do would be to press a button which activated a gesture-recognising glass pane over your internal frame, so you could then write glyphs by hand directly into the window, just like writing text with a marker on a normal whiteboard :o)

If you can get hold of a script-recognition library then that would be a really easy thing to do. And would ROCK.

itchyscratchya at 2007-7-9 22:54:27 > top of Java-index,Desktop,Core GUI APIs...
# 5

hehe yeah, its one of these: http://www2.smarttech.com/st/en-US/Products/SMART+Boards/Front+Projection/Default.htm

That feature would be awesome to implement, although the keyboard one would be faster to use in my opinion. Since the keyboard would be in a frame, I can stretch it and drag it so that it becomes comfortably small enough for me to type on, without having to go all over to the other side of the whiteboard for the 'a' button, then back again for the 'l' button.

Still, the visual keyboard would have a button that would expand the frame and include a white panel at which you could write your characters with the stylus (we even have different color ones, which makes drawing fun), then translate it to commands and/or letters.

alienchilda at 2007-7-9 22:54:27 > top of Java-index,Desktop,Core GUI APIs...