Skip to content
Snippets Groups Projects
Commit 7cc255e9 authored by Branden Boehr (bjb286)'s avatar Branden Boehr (bjb286)
Browse files

Merge branch 'feature-DetectProgram/LaunchApplication' into 'prototype'

Feature detect program/launch application

See merge request !48
parents 16c5e7ff a675a7db
No related branches found
No related tags found
2 merge requests!65Prototype,!48Feature detect program/launch application
# sample-data-repo
**Java Version: coretto-1.8_282**
# Required Libraries
JNA 5.7.02
Maven: net.java.dev.jna:jna:5.7.02
JNA Platform 5.7.02
Maven: net.java.dev.jna:jna-platform:5.7.02
ControlsFX 8.40.182
Maven: org.controlsfx:controlsfx:8.40.182
package model;
import java.io.IOException;
import java.io.InputStream;
import java.util.Scanner;
public class DetectProgram {
/**
*
* @param Name A string of the name of the program you wish to see if it is running.
* @return True if program is running or False if it isn't
*/
public static boolean isRunning(String Name) throws IOException {
ProcessBuilder processbuildier = new ProcessBuilder("tasklist.exe");
Process process = processbuildier.start();
String tasks = toString(process.getInputStream());
return tasks.contains(Name);
}
/**
* used for isRunning method to format Inputsteam into usable format.
* @param input unformatted string from InputStream
* @return the formatted string.
*/
public static String toString(InputStream input){
Scanner scan = new Scanner(input, "UTF-8").useDelimiter("\\A");
String output = scan.hasNext() ? scan.next() : "";
scan.close();
return output;
}
}
package model;
import java.awt.*;
import java.io.File;
import java.io.IOException;
public class LaunchApplication {
/**
* starts a program at the FilePath location if it isn't already running
* @param FilePath the absolute file path to the .exe of the program.
*/
public static void runApplication(String FilePath){
File application = new File(FilePath);
String Name = application.getName();
try {
boolean alreadyRunning = DetectProgram.isRunning(Name);
if(alreadyRunning == false){
Desktop.getDesktop().open(application);
}
}
catch (IOException ex){
System.out.println(ex.toString());
}
}
}
package model;
public class MediaKeys extends Hotkey implements InputEmulator{
// constant for testing
// Play/Pause Media Key: 0xB2
private static int play = Integer.decode("0xB2");
// Mute Media Key: 0xAD
private static int mute = Integer.decode("0xAD");
// Next Media Key: 0xB0
private static int next = Integer.decode("0xB0");
// Prev Media Key: 0xB1
private static int prev = Integer.decode("0xB1");
/**
* Constructs a hotkey
* @param keyCode Virtual keycode
* @param id id of hotkey
* @param modifier modifer for keycode
*/
public MediaKeys (int keyCode, int id, int modifier){
super(keyCode, id , modifier);
}
@Override
public void sendKey(int keyCode, boolean release){
if(keyCode == play){
System.out.println("sending Play keycode" + keyCode);
}
else if (keyCode == mute){
System.out.println("sending mute keycode" + keyCode);
}
else if (keyCode == next){
System.out.println("sending next keycode" + keyCode);
}
else if (keyCode == prev){
System.out.println("sending prev keycode" + keyCode);
}
}
public static void main(String[] args){
System.out.println("TestCases");
// with not valid keycode
MediaKeys test0 = new MediaKeys(0, 0, 0);
test0.sendKey(test0.getKeyCode(), false);
// with valid Keycode
MediaKeys test1 = new MediaKeys(178, 0, 0);
test1.sendKey(test1.getKeyCode(), false);
}
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment