Skip to content
This repository has been archived by the owner on Mar 14, 2018. It is now read-only.

Merging branch altgr support #184

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 7 additions & 9 deletions API/src/main/java/org/sikuli/basics/HotkeyManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,13 @@
*/
package org.sikuli.basics;

import org.sikuli.script.keyboard.KeyPress;
import org.sikuli.script.keyboard.KeyboardDelegator;

import java.awt.event.KeyEvent;
import java.lang.reflect.Constructor;
import java.util.HashMap;
import java.util.Map;
import org.sikuli.basics.Debug;
import org.sikuli.basics.PreferencesUser;
import org.sikuli.basics.Settings;
import org.sikuli.script.Key;
import org.sikuli.script.Key;

/**
* Singleton class to bind hotkeys to hotkey listeners
Expand Down Expand Up @@ -179,8 +177,8 @@ public boolean addHotkey(char key, int modifiers, HotkeyListener callback) {
* @return true if success. false otherwise.
*/
public boolean addHotkey(String key, int modifiers, HotkeyListener callback) {
int[] keyCodes = Key.toJavaKeyCode(key.toLowerCase());
int keyCode = keyCodes[0];
KeyPress keyPress = KeyboardDelegator.toJavaKeyCode(key.toLowerCase().charAt(0));
int keyCode = keyPress != null ? keyPress.getKeys()[0] : null;
return installHotkey(keyCode, modifiers, callback, "");
}

Expand Down Expand Up @@ -257,8 +255,8 @@ public boolean removeHotkey(char key, int modifiers) {
* @return true if success. false otherwise.
*/
public boolean removeHotkey(String key, int modifiers) {
int[] keyCodes = Key.toJavaKeyCode(key.toLowerCase());
int keyCode = keyCodes[0];
KeyPress keyPress = KeyboardDelegator.toJavaKeyCode(key.toLowerCase().charAt(0));
int keyCode = keyPress != null ? keyPress.getKeys()[0] : null;
return uninstallHotkey(keyCode, modifiers, "");
}

Expand Down
35 changes: 35 additions & 0 deletions API/src/main/java/org/sikuli/natives/CommandExecutorHelper.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package org.sikuli.natives;

import org.apache.commons.exec.CommandLine;
import org.apache.commons.exec.DefaultExecutor;
import org.apache.commons.exec.ExecuteException;
import org.apache.commons.exec.PumpStreamHandler;

import java.io.ByteArrayOutputStream;

public class CommandExecutorHelper {

public static CommandExecutorResult execute(String commandString, int expectedExitValue) throws Exception {
ByteArrayOutputStream error = new ByteArrayOutputStream();
ByteArrayOutputStream stout = new ByteArrayOutputStream();
CommandLine cmd = CommandLine.parse(commandString);
try {
DefaultExecutor executor = new DefaultExecutor();
executor.setExitValue(expectedExitValue);
executor.setStreamHandler(new PumpStreamHandler(stout, error));
//if exit value != expectedExitValue => Exception
int exitValue = executor.execute(cmd);
return new CommandExecutorResult(exitValue, stout.toString(), error.toString());

} catch (Exception e) {
int exitValue = -1;
if (e instanceof ExecuteException) {
exitValue = ((ExecuteException) e).getExitValue();
}
throw new NativeCommandException(
"error in command " + cmd.toString(),
new CommandExecutorResult(exitValue, stout.toString(), error.toString()));
}
}

}
25 changes: 25 additions & 0 deletions API/src/main/java/org/sikuli/natives/CommandExecutorResult.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package org.sikuli.natives;

public class CommandExecutorResult {
private int exitValue;
private String errorOutput;
private String standardOutput;

public CommandExecutorResult(int exitValue, String standardOutput, String errorOutput) {
this.exitValue = exitValue;
this.errorOutput = errorOutput;
this.standardOutput = standardOutput;
}

public int getExitValue() {
return exitValue;
}

public String getErrorOutput() {
return errorOutput;
}

public String getStandardOutput() {
return standardOutput;
}
}
Loading