Skip to content
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
Binary file modified Bundled Applications/Clickey.jar
Binary file not shown.
87 changes: 60 additions & 27 deletions src/ClickeyMain.java
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -2,41 +2,59 @@
import org.jnativehook.NativeHookException;
import org.jnativehook.keyboard.NativeKeyEvent;
import org.jnativehook.keyboard.NativeKeyListener;
import org.jnativehook.mouse.NativeMouseEvent;
import org.jnativehook.mouse.NativeMouseListener;

import javax.sound.sampled.*;
import java.io.BufferedInputStream;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;

public class ClickeyMain implements NativeKeyListener {

Clip clip;
AudioInputStream audioIn;
public class ClickeyMain implements NativeKeyListener, NativeMouseListener {

public static final int BACK = 14;
public static final int SPACE = 57;

public void load(NativeKeyEvent e) throws IOException, LineUnavailableException, UnsupportedAudioFileException {
String filePath = "";
public void playSoundForKey(NativeKeyEvent e) {
if (e.getKeyCode() == BACK) {
filePath = "/sounds/key_press_delete.wav";
playSound("key_press_delete.wav");
} else if (e.getKeyCode() == SPACE) {
filePath = "/sounds/key_press_modifier.wav";
playSound("key_press_modifier.wav");
} else {
filePath = "/sounds/key_press_click.wav";
playSound("key_press_click.wav");
}
InputStream audioSrc = getClass().getResourceAsStream(filePath);
InputStream bufferedIn = new BufferedInputStream(audioSrc);
audioIn = AudioSystem.getAudioInputStream(bufferedIn);
clip = AudioSystem.getClip();
clip.open(audioIn);
clip.start();
}

void playSound(String filePath) {
try
{
filePath = "/sounds/"+filePath;
InputStream audioSrc = getClass().getResourceAsStream(filePath);
InputStream bufferedIn = new BufferedInputStream(audioSrc);
AudioInputStream audioIn = AudioSystem.getAudioInputStream(bufferedIn);
final Clip clip = AudioSystem.getClip();
clip.addLineListener(new LineListener()
{
@Override
public void update(LineEvent event)
{
if (event.getType() == LineEvent.Type.STOP)
{
clip.close();
}
}
});
clip.open(audioIn);
clip.start();
} catch (Exception e)
{
e.printStackTrace();
}
}


public void nativeKeyPressed(NativeKeyEvent e) {
System.out.println(e.getKeyCode());

if (e.getKeyCode() == NativeKeyEvent.VC_ESCAPE) {
try {
Expand All @@ -45,26 +63,38 @@ public void nativeKeyPressed(NativeKeyEvent e) {
e1.printStackTrace();
}
} else {
try {
load(e);
} catch (IOException e1) {
e1.printStackTrace();
} catch (LineUnavailableException e1) {
e1.printStackTrace();
} catch (UnsupportedAudioFileException e1) {
e1.printStackTrace();
}
playSoundForKey(e);
}
}

public void nativeKeyReleased(NativeKeyEvent e) {
clip.stop();

}

public void nativeKeyTyped(NativeKeyEvent e) {

}

public void nativeMouseClicked(NativeMouseEvent e) {

}

public void nativeMousePressed(NativeMouseEvent e) {
playSound("mouse_pressed.wav");
}

public void nativeMouseReleased(NativeMouseEvent e) {
playSound("mouse_released.wav");
}

public void nativeMouseMoved(NativeMouseEvent e) {

}

public void nativeMouseDragged(NativeMouseEvent e) {

}

public static void main(String[] args) {
try {
GlobalScreen.registerNativeHook();
Expand All @@ -75,7 +105,10 @@ public static void main(String[] args) {
System.exit(1);
}

GlobalScreen.addNativeKeyListener(new ClickeyMain());
ClickeyMain instance = new ClickeyMain();
GlobalScreen.addNativeKeyListener(instance);
GlobalScreen.addNativeMouseListener(instance);

}

}
Expand Down
Binary file added src/sounds/mouse_pressed.wav
Binary file not shown.
Binary file added src/sounds/mouse_released.wav
Binary file not shown.