Last night I got my Mac to understand me when I said basic poker terms like "Fold", "Call", and "Raise". This evening I took the idea a bit further. What if, when I said "Fold", my Java program would fold my hand for me?
This should be a insanely easy task using AppleScript. Unfortunately none of the poker room clients seem to be scriptable. But if I know where the "Fold" button is, perhaps I could tell my Mac to simulate a mouse click on that spot?
That was the idea. Surprisingly it works. I found a tiny Mac program that simulates mouse clicks, even in non-scriptable applications.
I opened a poker table at Full Tilt and used Pixie to measure the locations of the Fold, Check, Raise, and Call buttons. Then I got my Java program to click at the right spot for each word.
Did it work? You betcha! It was cool saying "Fold" and watching it work.
Here's the code that does most of the work:
private static void setUpSpeechRecognition() {
SpeechRecognizer speechRecognizer = new SpeechRecognizer();
speechRecognizer.setSpeechRecognizerListener(
new SpeechRecognizerListener() {
public void didRecognizeCommand(String command) {
if (command.equals("Fold")) {
click(627, 704);
} else if (command.equals("Check")) {
click(627, 704);
} else if (command.equals("Raise")) {
click(864, 704);
} else if (command.equals("Call")) {
click(750, 704);
}
}
});
speechRecognizer.setCommands("Fold", "Check", "Raise", "Call");
speechRecognizer.setListensInForegroundOnly(false);
speechRecognizer.setDisplayedCommandsTitle("Poker Copilot");
speechRecognizer.startListening();
}
private static void click(final int x, final int y) {
try {
Robot robot = new Robot();
robot.mouseMove(x, y);
robot.mousePress(InputEvent.BUTTON1_MASK);
robot.mouseRelease(InputEvent.BUTTON1_MASK);
} catch (AWTException e) {
throw new RuntimeException(e);
}
}
The next task: determining programmatically the location of the command buttons at a poker table.


8 comments:
That's very cool. I do something Selenium of sorts to test my Webapp, but for some thing I need to simulate mouseclicks.
I don't know much about recocoa/JNA. Could you show your click method and say if I should use recocoa or JNA or JNI?
Thanks a lot, cool blog entry!
@Anonymous,
I've updated the blog post to include the click method.
Regards,
Steve
---------------------------------------------------
Steve McLeod
Founder, Poker Copilot
http://www.pokercopilot.com
Oh but now I'm confused... You're just using the regular Java Robot to do that, not the cocoa/recocoa/JNA/JNI calls. This has nothing to do with the tiny Mac program that simulates mouse clicks: Robot works on Windows and Linux too.
With the Java Robot you see the mouse pointer jumping around.
Can't this be done using another way so that the mouse pointer isn't seen moving around?
That is: simulating a click but without needing to do a mouveMove first?
@Anonymous,
Yeah I changed it to use Robot.
I originally had this:
new ProcessBuilder("./click", "-x", Integer.toString(x) + "", "-y", Integer.toString(y)).start();
Which just runs the click binary I linked to.
But this still moves the actual mouse. You could record where the mouse is, move it, then return it to the original position.
Thanks Steve, I appreciate you taking the time to help me with this.
Do you know if using directly CGEvent... it would be possible to actually simulate a click *without* having to mouse the move?
I'd really like to do that without seeing my mouse pointer moving around.
From the 'clicclick' command I tried, it seems you can do it without seeing the mouse pointer moving, but I'm not sure when calling CGEvent... from Java.
@Anonymous,
I don't know much about CGEvent but in my own test code that used CGEvent the mouse moved, but invisibly.
Regards,
Steve
---------------------------------------------------
Steve McLeod
Founder, Poker Copilot
http://www.pokercopilot.com
This is awesome Steve! If you can make it more robust, that would be cool.
Lots of mac folks been waiting a long time for some sort of auto hotkey program. Would you be able to set more than 1 location for multi tabling?
Post a Comment