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 11 of 11

Thread: combining keys

  1. #1
    Member
    Join Date
    Aug 2009
    Posts
    38
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question combining keys

    How to combine two keys in keypressed() event?


  2. #2
    Super Moderator Json's Avatar
    Join Date
    Jul 2009
    Location
    Warrington, United Kingdom
    Posts
    1,274
    My Mood
    Happy
    Thanks
    70
    Thanked 156 Times in 152 Posts

    Default Re: combining keys

    I take it there will be two events, one for each key.

    So for instance if you wish to check for CTRL + G being pushed you will have to do something like this.

    1) Create code that sets a boolean to true if CTRL is pressed down, and set it back to false if the button is released
    2) Create code that sets a boolean to true if G is pressed down, and set it back to false if the button is released
    3) At each event, check if CTRL and G booleans are true and then you will know they both where pressed at the same time.

    I think....

    // Json

  3. #3
    mmm.. coffee JavaPF's Avatar
    Join Date
    May 2008
    Location
    United Kingdom
    Posts
    3,336
    My Mood
    Mellow
    Thanks
    258
    Thanked 287 Times in 225 Posts
    Blog Entries
    4

    Default Re: combining keys

    Quote Originally Posted by subhvi View Post
    How to combine two keys in keypressed() event?
    Do you mean like Ctrl + F5?
    Please use [highlight=Java] code [/highlight] tags when posting your code.
    Forum Tip: Add to peoples reputation by clicking the button on their useful posts.

    Looking for a Java job? Visit - Java Programming Careers

  4. #4
    Member
    Join Date
    Aug 2009
    Posts
    38
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question Re: combining keys

    Yes, the same thing JavaPF.Its working now.Thanks Json & JavaPF.But i have another doubt.Suppose i don't want the default action for keys like,
    CONTROL+V is for paste.But i don't want to do this action.It have to perform some custom events.Is this possible?

  5. #5
    mmm.. coffee JavaPF's Avatar
    Join Date
    May 2008
    Location
    United Kingdom
    Posts
    3,336
    My Mood
    Mellow
    Thanks
    258
    Thanked 287 Times in 225 Posts
    Blog Entries
    4

    Default Re: combining keys

    Quote Originally Posted by subhvi View Post
    Yes, the same thing JavaPF.Its working now.Thanks Json & JavaPF.But i have another doubt.Suppose i don't want the default action for keys like,
    CONTROL+V is for paste.But i don't want to do this action.It have to perform some custom events.Is this possible?
    To be honest I have no idea. I don't think you can change what actions are performed for the default key shortcuts in Windows.
    Please use [highlight=Java] code [/highlight] tags when posting your code.
    Forum Tip: Add to peoples reputation by clicking the button on their useful posts.

    Looking for a Java job? Visit - Java Programming Careers

  6. #6
    Senile Half-Wit Freaky Chris's Avatar
    Join Date
    Mar 2009
    Location
    Wales, Bangor & England, Warwickshire
    Posts
    820
    My Mood
    Cynical
    Thanks
    7
    Thanked 104 Times in 90 Posts

    Default Re: combining keys

    Something such as Ctrl-C is not a Windows default, its just a well recognised practise by windows. Each application has to interpret Ctrl-C in its own way...it doesn't have to do it. But either way you would have to interupt keyboard input at a system level, then do what ever and stop the message being passed on.

    Not possible with standalone Java

    Chris
    Last edited by Freaky Chris; August 28th, 2009 at 07:51 AM.
    chris[at]javaprogrammingforums[dot]com

    Prifysgol Bangor University, North Wales

  7. #7
    mmm.. coffee JavaPF's Avatar
    Join Date
    May 2008
    Location
    United Kingdom
    Posts
    3,336
    My Mood
    Mellow
    Thanks
    258
    Thanked 287 Times in 225 Posts
    Blog Entries
    4

    Default Re: combining keys

    Quote Originally Posted by Freaky Chris View Post
    Something such as Ctrl-C is not a Windows default, its just a well recognised practise by windows. Each application has to interpret Ctrl-C in its own way...it doesn't have to do it. But either way you would have to interupt keyboard input at a system level, then do what ever and stop the message being passed on.

    Not possible with standalone Java

    Chris
    Complicated either way!
    Please use [highlight=Java] code [/highlight] tags when posting your code.
    Forum Tip: Add to peoples reputation by clicking the button on their useful posts.

    Looking for a Java job? Visit - Java Programming Careers

  8. #8
    Senile Half-Wit Freaky Chris's Avatar
    Join Date
    Mar 2009
    Location
    Wales, Bangor & England, Warwickshire
    Posts
    820
    My Mood
    Cynical
    Thanks
    7
    Thanked 104 Times in 90 Posts

    Default Re: combining keys

    Why does everything I post in end with me mentionng JNI nowdays

    Chris
    chris[at]javaprogrammingforums[dot]com

    Prifysgol Bangor University, North Wales

  9. #9
    mmm.. coffee JavaPF's Avatar
    Join Date
    May 2008
    Location
    United Kingdom
    Posts
    3,336
    My Mood
    Mellow
    Thanks
    258
    Thanked 287 Times in 225 Posts
    Blog Entries
    4

    Default Re: combining keys

    Quote Originally Posted by Freaky Chris View Post
    Why does everything I post in end with me mentionng JNI nowdays

    Chris
    Because your a C monkey!
    Please use [highlight=Java] code [/highlight] tags when posting your code.
    Forum Tip: Add to peoples reputation by clicking the button on their useful posts.

    Looking for a Java job? Visit - Java Programming Careers

  10. #10
    Senile Half-Wit Freaky Chris's Avatar
    Join Date
    Mar 2009
    Location
    Wales, Bangor & England, Warwickshire
    Posts
    820
    My Mood
    Cynical
    Thanks
    7
    Thanked 104 Times in 90 Posts

    Default Re: combining keys

    C++...not used it in ages though really lol!
    chris[at]javaprogrammingforums[dot]com

    Prifysgol Bangor University, North Wales

  11. #11
    Super Moderator helloworld922's Avatar
    Join Date
    Jun 2009
    Posts
    2,896
    Thanks
    23
    Thanked 619 Times in 561 Posts
    Blog Entries
    18

    Default Re: combining keys

    Lol, i've forgotten much of the C++ syntax. The other day, i tried doing this:
    // I know it says Java Code, but I was doing this in C++
    public class Date
    {
         String month;
         int day;
         int year;
        // ... rest of code
    }

Similar Threads

  1. List of shortcuts key for Eclipse
    By Flash in forum Java JDK & IDE Tutorials
    Replies: 3
    Last Post: July 18th, 2013, 08:40 AM