Is it possible to set/move the mouse pointer's location directly from Mathematica without using external tools like Run["xdotool mousemove x y"]?
Asked
Active
Viewed 2,388 times
23
rm -rf
- 88,781
- 21
- 293
- 472
my account_ram
- 2,158
- 11
- 25
-
2If an interactive application like Mathematica did that, I would consider it a bug... Anyway, I don't think it's possible from within Mathematica. – Jens Aug 12 '12 at 02:50
-
You don't mean setting the current insertion point or selection? – Sjoerd C. de Vries Aug 12 '12 at 06:55
-
not the selection inside Mathematica. Just moving the mouse pointer anywhere inside the screen – my account_ram Aug 15 '12 at 06:34
1 Answers
40
Needs["JLink`"]
ReinstallJava[]
robotclass=JavaNew["java.awt.Robot"]
robotclass@mouseMove[#,300]&/@Range@900;
rm -rf
- 88,781
- 21
- 293
- 472
Andreas Lauschke
- 4,009
- 22
- 20
-
3
-
1
-
5+1 Great ;-)
Table[robotclass@mouseMove[Round[300 (Cos[x] + 1)], Round[100 (Sin[2 x] + 1)]], {x, 0, 2 Pi, .001}];– Vitaliy Kaurov Aug 21 '12 at 01:25 -
Excellent - that seems like a prime candidate for causing some desktop mischief ;-) – Yves Klett Aug 21 '12 at 07:00
-
-
2
-
-
Linking to Java is not considered using an external tool? Interesting.... – John Nov 11 '13 at 01:31
-
2@John: No, it's not. a) in the example of the o/p xdotool would be an external tool/application/program that you'd need to call. b) JLink is part of M, and WRI's official position is that this makes all of Java part of M (same with NETLink and .Net), as indicated by marketing materials. c) you ARE actually writing this in M. My code above is NOT Java code, it's M code. It just LOOKs like Java code (and that's a smart design choice of JLink/NETLink), but it isn't. These are all M symbols, it's M syntax, it runs from the M f/e, and it is executed/"scripted" through the kernel. – Andreas Lauschke Nov 11 '13 at 16:03