0

Here is a possible example of what I am trying to do.

if (/* the user presses Alt+e*/) {
Process a = Runtime
.getRuntime()
.exec("rundll32 url.dll,FileProtocolHandler C:\\blah\\blah\\blah\\abc.bat");
a.waitFor();
// or something else
}

The above code is meant to run a file abc.bat if the user presses Alt+e. I can't figure out what to put in the "if" statement. The "then" part of the code is not relevant to the question here, it is just an example. I am new to Java and I googled a lot before asking this question but anything I found that seemed relevant contained terms and statements that I couldn't understand in the explanation of the code mentioned there which made me suspect that it was about something different than what I am trying to do, so can anyone please help me here with the required code to put inside the "if" and perhaps explain it also in easy English. And if if-then-else is not the way to this then I am open to other solutions.

  • 1
    If you have a GUI you should look for ActionMap, if you trying to bind it to the system so I don't know except native – Marcos Vasconcelos Feb 20 '18 at 16:42
  • 2
    Is it a GUI based application or not? – Federico Scardina Feb 20 '18 at 16:45
  • @Federico Scardina ok i think i understand what u r asking. the stuff in the then brackets needs to happen WHENEVER i press Alt+e no matter what i am doing on my laptop. I want to complie that java code into a jar file and put that file in my startup folder to make it easier for me to do stuff I do everyday/a lot. And it has to be Java. Please don't suggest something like AutoHotkey. –  Feb 20 '18 at 17:19
  • @user9354584 You cannot do that in a "native" way if you have a no-GUI application, because you need integration with the OS to achieve your goal. Try to use something like AutoIt like this: https://stackoverflow.com/a/19802582/8081032 – Federico Scardina Feb 21 '18 at 10:07
  • @FedericoScardina I have already done this in a "native" way using AutoHotkey which is like Autoit. I want to redo this stuff with a proper programming language like C++, Python, etc and I thought Java would do the trick. Thanks for helping me realize my mistake. So what language can I use for this? If u know please tell. If not, thanks anyway. –  Feb 21 '18 at 11:23
  • @user9354584 I suggest you to use Python, it'simple and fast. You can use [pyhk](http://schurpf.com/python/python-hotkey-module/) library to achieve your goal. – Federico Scardina Feb 21 '18 at 12:06

0 Answers0