How can I track the pressing of two or more keys?












0














I need to track a combination of two buttons. I wrote this code, but it does not work correctly.



primaryStage.addEventFilter(KeyEvent.KEY_PRESSED, new EventHandler<KeyEvent>(){
public void handle(KeyEvent event){
if(event.getCode() == UP && event.getCode() == RIGHT){camera.cameraControlXY(-0.5,0.5);};
}
});


In the sample code there is only one function, in the full code there are other functions, separately for each key. When you press a combination, functions for individual keys are triggered. I found similar questions, but the answers did not clarify the situation. I saw a lot of similar listeners for pressing buttons and I don’t really understand how they differ. thanks in advance for your reply










share|improve this question


















  • 2




    Use a Set. On each key press, you put the key in the Set, on each release, you remove it. You then have a "processing" method which make determinations about what to do based on what's in the Set
    – MadProgrammer
    Nov 11 at 23:34










  • As @MadProgrammer said, using Set can help you. A bit more info can be found here
    – Sai Dandem
    Nov 11 at 23:44










  • OK I understood. I will deal with it. And you could not even poke where to look, to understand how to track the duration of pressing a key?@MadProgrammer
    – lalalend
    Nov 11 at 23:49
















0














I need to track a combination of two buttons. I wrote this code, but it does not work correctly.



primaryStage.addEventFilter(KeyEvent.KEY_PRESSED, new EventHandler<KeyEvent>(){
public void handle(KeyEvent event){
if(event.getCode() == UP && event.getCode() == RIGHT){camera.cameraControlXY(-0.5,0.5);};
}
});


In the sample code there is only one function, in the full code there are other functions, separately for each key. When you press a combination, functions for individual keys are triggered. I found similar questions, but the answers did not clarify the situation. I saw a lot of similar listeners for pressing buttons and I don’t really understand how they differ. thanks in advance for your reply










share|improve this question


















  • 2




    Use a Set. On each key press, you put the key in the Set, on each release, you remove it. You then have a "processing" method which make determinations about what to do based on what's in the Set
    – MadProgrammer
    Nov 11 at 23:34










  • As @MadProgrammer said, using Set can help you. A bit more info can be found here
    – Sai Dandem
    Nov 11 at 23:44










  • OK I understood. I will deal with it. And you could not even poke where to look, to understand how to track the duration of pressing a key?@MadProgrammer
    – lalalend
    Nov 11 at 23:49














0












0








0







I need to track a combination of two buttons. I wrote this code, but it does not work correctly.



primaryStage.addEventFilter(KeyEvent.KEY_PRESSED, new EventHandler<KeyEvent>(){
public void handle(KeyEvent event){
if(event.getCode() == UP && event.getCode() == RIGHT){camera.cameraControlXY(-0.5,0.5);};
}
});


In the sample code there is only one function, in the full code there are other functions, separately for each key. When you press a combination, functions for individual keys are triggered. I found similar questions, but the answers did not clarify the situation. I saw a lot of similar listeners for pressing buttons and I don’t really understand how they differ. thanks in advance for your reply










share|improve this question













I need to track a combination of two buttons. I wrote this code, but it does not work correctly.



primaryStage.addEventFilter(KeyEvent.KEY_PRESSED, new EventHandler<KeyEvent>(){
public void handle(KeyEvent event){
if(event.getCode() == UP && event.getCode() == RIGHT){camera.cameraControlXY(-0.5,0.5);};
}
});


In the sample code there is only one function, in the full code there are other functions, separately for each key. When you press a combination, functions for individual keys are triggered. I found similar questions, but the answers did not clarify the situation. I saw a lot of similar listeners for pressing buttons and I don’t really understand how they differ. thanks in advance for your reply







java javafx






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 11 at 23:30









lalalend

156




156








  • 2




    Use a Set. On each key press, you put the key in the Set, on each release, you remove it. You then have a "processing" method which make determinations about what to do based on what's in the Set
    – MadProgrammer
    Nov 11 at 23:34










  • As @MadProgrammer said, using Set can help you. A bit more info can be found here
    – Sai Dandem
    Nov 11 at 23:44










  • OK I understood. I will deal with it. And you could not even poke where to look, to understand how to track the duration of pressing a key?@MadProgrammer
    – lalalend
    Nov 11 at 23:49














  • 2




    Use a Set. On each key press, you put the key in the Set, on each release, you remove it. You then have a "processing" method which make determinations about what to do based on what's in the Set
    – MadProgrammer
    Nov 11 at 23:34










  • As @MadProgrammer said, using Set can help you. A bit more info can be found here
    – Sai Dandem
    Nov 11 at 23:44










  • OK I understood. I will deal with it. And you could not even poke where to look, to understand how to track the duration of pressing a key?@MadProgrammer
    – lalalend
    Nov 11 at 23:49








2




2




Use a Set. On each key press, you put the key in the Set, on each release, you remove it. You then have a "processing" method which make determinations about what to do based on what's in the Set
– MadProgrammer
Nov 11 at 23:34




Use a Set. On each key press, you put the key in the Set, on each release, you remove it. You then have a "processing" method which make determinations about what to do based on what's in the Set
– MadProgrammer
Nov 11 at 23:34












As @MadProgrammer said, using Set can help you. A bit more info can be found here
– Sai Dandem
Nov 11 at 23:44




As @MadProgrammer said, using Set can help you. A bit more info can be found here
– Sai Dandem
Nov 11 at 23:44












OK I understood. I will deal with it. And you could not even poke where to look, to understand how to track the duration of pressing a key?@MadProgrammer
– lalalend
Nov 11 at 23:49




OK I understood. I will deal with it. And you could not even poke where to look, to understand how to track the duration of pressing a key?@MadProgrammer
– lalalend
Nov 11 at 23:49

















active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53254308%2fhow-can-i-track-the-pressing-of-two-or-more-keys%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown






























active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53254308%2fhow-can-i-track-the-pressing-of-two-or-more-keys%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







這個網誌中的熱門文章

Tangent Lines Diagram Along Smooth Curve

Yusuf al-Mu'taman ibn Hud

Zucchini