I'm trying to simulate key presses using XHB and XTest, using this example code as a reference. Unfortunately, whatever I do, the resulting program has no effect. No exceptions, no warnings.
Any ideas?
I'm using XHB 0.5.2012.11.23 with GHC 7.4.1 on Ubuntu 12.04.
Here's what I've got so far:
import Control.Monad
import Control.Concurrent
import Graphics.XHB
import Graphics.XHB.Gen.Test
main = do
Just c <- connect
let keyCode = 38 -- A
forever $ do
fakeInput c $ MkFakeInput (toBit' EventMaskKeyPress) keyCode 0 (fromXid xidNone) 0 0 0
threadDelay $ 1 * 1000
fakeInput c $ MkFakeInput (toBit' EventMaskKeyRelease) keyCode 0 (fromXid xidNone) 0 0 0
threadDelay $ 1 * 1000
toBit' :: (BitEnum a, Integral b) => a -> b
toBit' = fromIntegral . toBit
The issue here is a bit subtle. If you look at the XTest protocol you'll find that the FAKE_EVENT
doesn't expect an EVENT_MASK
but instead expects a FAKE_EVENT_TYPE
. KeyPress
is FAKE_EVENT_TYPE
2
whereas KeyRelease
is 3
. Things work as expected after these values are used in place of EventMaskKeyPress
and EventMaskKeyRelease
(moreover, you don't need the nasty toBit
coercion, which was the smell that pointed me towards this being incorrect).