Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 8 of 8

Thread: Key bindings capture

  1. #1
    Member Zyrion's Avatar
    Join Date
    Feb 2013
    Location
    Iowa
    Posts
    106
    My Mood
    Angelic
    Thanks
    2
    Thanked 8 Times in 8 Posts

    Default Key bindings capture

    In my program, I am trying to capture a particular set of keys. In theory, I would like to set up a thread and buffer that will scan through the input send by the keyboard. When a match is made, it will throw it back to the main method. My question is: What is the name of the class that will assist in setting up a input capture via keyboard?


  2. #2

  3. The Following User Says Thank You to copeg For This Useful Post:

    Zyrion (October 23rd, 2013)

  4. #3
    Member Zyrion's Avatar
    Join Date
    Feb 2013
    Location
    Iowa
    Posts
    106
    My Mood
    Angelic
    Thanks
    2
    Thanked 8 Times in 8 Posts

    Default Re: Key bindings capture

    I read the article about the key listener, particularly the event of 'The typing of a unicode character.' From what I have learned, a key listener event is fired from a component, when it is in focus. So this leads to my next question, how can I have a component fire keyboard events from a window that is seperate from the application's components? For example, when I type 'go' in my browser, a keyboard listener event is fired? Would I have to set my browser in focus in the application? Is that possible?

  5. #4
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,332
    Thanks
    181
    Thanked 829 Times in 772 Posts
    Blog Entries
    5

    Default Re: Key bindings capture

    So this leads to my next question, how can I have a component fire keyboard events from a window that is seperate from the application's components? For example, when I type 'go' in my browser, a keyboard listener event is fired? Would I have to set my browser in focus in the application? Is that possible?
    Sounds a little bit phishy, but be that as it may if I understand correctly you will most likely have to use JNI

  6. #5
    Member Zyrion's Avatar
    Join Date
    Feb 2013
    Location
    Iowa
    Posts
    106
    My Mood
    Angelic
    Thanks
    2
    Thanked 8 Times in 8 Posts

    Default Re: Key bindings capture

    My intentions are not to record the key strokes of a user maliciously (if that is what it seems like.) I was just giving an example. Let me clarify, I have a computer game application that runs effectively in a Full-Screen resolution. It would be cumbersome for the user to minimize the entire entity in order to adjust the GUI. So instead, it would be easier to invoke particular methods by using the keyboard (keybindings or key strokes). So for example, while playing chess I type ":start" or "ctrl + alt + st" while in the program window, in order to invoke a timer method or a paint method. I will also take a look at the JNI and report back.

  7. #6
    Member Zyrion's Avatar
    Join Date
    Feb 2013
    Location
    Iowa
    Posts
    106
    My Mood
    Angelic
    Thanks
    2
    Thanked 8 Times in 8 Posts

    Default Re: Key bindings capture

    At the moment, I am writing a C++ application that has successfully fired events from particular key bindings set to my game application. However, I am having trouble getting my java classes to utilize this C++ class. To elaborate, how does one call a C++ class from a java application?

    Please note, I have made an attempt on researching this via google but to no avail. I have not found an article that has explained the process well enough for me to understand it. If you could please explain the process logically or link me to the available article, I would appreciate it.

  8. #7
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,751
    My Mood
    Mellow
    Thanks
    233
    Thanked 711 Times in 697 Posts

    Default Re: Key bindings capture

    You're calling the C++ executable, right? This topic is covered from several angles on StackOverflow. Search, "call executable from java" or similar.

    Why is Java involved at all? Or, if all that is needed is the C++ key binding code, why not rewrite the C++ code in Java?

    Re-reading your posts, you're kind of all over the place. Do you want to write the required code in Java as in Post #3? If so, what you describe is not that hard. Post your code up to the "go" part, and we'll see what can be done with it.

  9. #8
    Member Zyrion's Avatar
    Join Date
    Feb 2013
    Location
    Iowa
    Posts
    106
    My Mood
    Angelic
    Thanks
    2
    Thanked 8 Times in 8 Posts

    Default Re: Key bindings capture

    I believe I have found a re-usable solution. By creating a Java wrapper for the C++ class.

    JNI- Subclass a C++ class in Java using JNI

    I shall return with questions if I am having trouble doing this. Though, I believe I won't with that much information.

Similar Threads

  1. JOGL java bindings resources
    By lilroo in forum Member Introductions
    Replies: 2
    Last Post: September 10th, 2011, 06:27 PM
  2. Replies: 1
    Last Post: February 10th, 2011, 07:57 AM
  3. Key Bindings
    By nemo in forum What's Wrong With My Code?
    Replies: 2
    Last Post: December 28th, 2010, 07:50 PM
  4. Question...Key bindings
    By TheEnd in forum What's Wrong With My Code?
    Replies: 1
    Last Post: January 19th, 2010, 08:10 PM