From: Erik Veenstra Date: 2005-07-30T20:11:02+09:00 Subject: Re: Simulating Mouse Dragging > > > > Is it possible to simulate a mouse drag event in a > > > > browser (or any program in general) with Ruby? > > > > Something like: > > > > > > Could recording + analyzing mouse data help? Then you can > > > simulate it and let X11 consume it. `gpm -R` may help. > > > > "Recording" the mouse data by reading /dev/gpmdata actually > > works. Good start. Generating such a data stream is > > possible. But what do we have to do to let X11 "consume" > > that stream? "cat test /dev/gpmdata" doesn't work... > > disclaimer: I have never tried anything like this myself. > > In what sense does it not work? (assuming you made X11 read > /dev/gpmdata one way or the other). I would guess that `cat > test` is "too fast". I experimented a bit, yesterday night. I didn't configure X11 to read from /dev/gpmdata. But I found that one. After that, writing to /dev/gpmdata with a properly (?) filled memory structure, actually did move the mouse. Clicking was possible, too. But dragging somehow still doesn't work. The protocol is IMPS/2. I attached my experiment. Somebody able and willing to help? gegroet, Erik V. - http://www.erikveen.dds.nl/ ---------------------------------------------------------------- # http://www.mit.edu:8001/people/gassend/protocols/intellimouse/ # http://www.microsoft.com/whdc/device/input/mcompat.mspx class Mouse Yov = 0x80 Xov = 0x40 Y8 = 0x20 X8 = 0x10 BIT4 = 0x08 MB = 0x04 RB = 0x02 LB = 0x01 def initialize @handle = File.new("/dev/gpmdata", "wb") @handle.sync = true @button = 0 end def move(dx, dy) @bytes = [] byte1 = (BIT4 | @button) byte2 = (dx.to_i) byte3 = (dy.to_i) byte4 = 0 if dx < 0 byte1 |= X8 byte2 += 256 end if dy < 0 byte1 |= Y8 byte3 += 256 end @bytes << byte1 @bytes << byte2 @bytes << byte3 @bytes << byte4 send end def down(button) @button = button move(0, 0) end def up @button = 0 move(0, 0) end def drag(dx, dy, button) down(button) move(dx, dy) up end def click(button) down(button) up end def stream @bytes.pack("c%d" % @bytes.length) end def inspect @bytes.collect{|s| s.chr}.join("").unpack("H2"*@bytes.length) end def send p inspect @handle << stream end end #system "sudo /etc/init.d/gpm stop" or puts "Oops" mouse = Mouse.new mouse.drag(-100, 0, Mouse::LB) mouse.move(+100, 0) #system "sudo /etc/init.d/gpm start" or puts "Oops" ----------------------------------------------------------------