Haskell and java.awt.Robot
I'm interested in writing a program that takes control of keyboard and mouse in much the same way that one can with java.awt.Robot. I assume of co开发者_JS百科urse that there's no way to do this with standard libraries. Does anyone know of a good library I can connect to by means of FFI to achieve something like this?
I don't have any relevant experience, sorry. My first thought would be to look at other UI libraries, such as GTK,
- http://developer.gnome.org/gdk/stable/GdkDisplay.html#gdk-display-warp-pointer
It looks like this may be already exported to Haskell via gtk2hs. If you know how to use the C foreign function interface, the XTest extension library seems to have what you want. ( http://www.x.org/releases/X11R7.6/doc/libXtst/xtestlib.html ).
If you're running this in Windows take a look at Win32::GuiTest. In X11 you can use X11::GuiTest. Both are Perl wrappers over native system calls.
If you use X11, you can use either XTest or the higher level Robot.
Here's an example of XTest:
import Control.Concurrent (threadDelay)
import Control.Monad (forever)
import Graphics.X11.Xlib
import Graphics.X11.XTest
main = withDisplay "" $ \dpy -> forever $ do
sendKey dpy [] xK_a
threadDelay (500 * 1000)
and here's an example of Robot:
import Control.Monad (forever)
import Test.Robot
main = runRobot . forever $ do
tap _A
sleep 0.5
精彩评论