0

I would like to create a little program in Java that runs in the background and that detects a certain combination of pressed keys (in my case the space bar) and that after getting a space bar, sends a ctrl+c and and a to a Prolog console command to abort a prolog command that is going to be running. Would that be possible to be done?

Thanks a lot in advance!

noloman
  • 11,411
  • 20
  • 82
  • 129

1 Answers1

1

I think in Java you can only send inputs when you have focus in that Java application, so probably your only solution would be to implement that in C or C++ instead, or even to use other languages specialized for the automatic creation of input events to other applications, to simplify your work.

Hope that helps.

Luis Miguel Serrano
  • 5,029
  • 2
  • 41
  • 41
  • Well as I am using Processing (processing.org) I think you can run several "scripts" at the same time (not sure though), but in chat my program can do that, how would I be supposed to do it? Thanks! – noloman Dec 19 '10 at 17:43
  • What do you mean with "in chat my program can do that" ? What I meant is that I think a Java application cannot send input directly into another application that was not started from within that Java program. For example, if you have a chat Java application, then sure you can have it listen for specific keys, but that is because when you are using it, it has focus and the keys you pas to the OS will be passed to the Java application. At most, you can set it to not consume those inputs, so that they can be captured by other applications too, but it doesn't work the other way around. – Luis Miguel Serrano Dec 19 '10 at 20:34
  • Sorry it was a typo :) I am planning to launch a SICStus prolog application from Java (actually from Processing) and this sicstus prolog will receive input from the user by a keyboard.. so probably it should have the focus, but actually in the screen, the user should be seeing a visualization made in processing, while processing itself is in a loop waiting for the space bar to stop the prolog thing.. but now I think about it, would this be possible to be made? – noloman Dec 20 '10 at 13:22
  • Well, if the prolog application launched from Java is capable of catching that spacebar and generating some output your java application can capture and react to, using the prolog's Process object in java with the .getOutputStream() method or exitValue() [in case the prolog application itself can exit on space bar], then you can. – Luis Miguel Serrano Dec 20 '10 at 18:29