Simulating button pressed/released events
Andrew Conroy (370) 740 posts |
I’m trying to simulate a mouse, which requires me to insert button pressed/released events. I’m using OS_CallAVector to insert key pressed/released events via KeyV. This works fine for click & release or click and drag type actions, but for a double-click, this is being interpreted as a shift-double-click, so apps are opened rather than run. I’ve tried inserting mouse clicks into the mouse buffer, but this doesn’t seem to allow me to have a click and hold action to allow dragging. Any idea how to simulate a proper double-click rather than a shift-double-click? I’m guessing it’s to do with the Wimp not knowing the time between click events, so maybe interpreting it as click-and-hold which would be the same as shift-double-click? Oh, and I’m currently doing this from a multi-tasking wimp app in BASIC! |
Rik Griffin (98) 264 posts |
I’ve done this sort of thing before, when I wrote a VNC-alike type thing. Referring back to my old code – which is in C but I can post snippets if you like – here are some brief notes: Insert mouse events into the buffer using OS_Byte 138. Each mouse event has an x and y coordinate, button state and a timestamp (OS_ReadMonotonicTime) To simulate a double click insert 4 events: button down, release, button down, release. To simulate a drag insert 3 events: button down at position 1, button down at pos 2, then release at pos 2. To simulate modifier keys (shift, ctrl, alt) use OS_CallAVector to insert the key pressed event via KeyV, then insert a key released event on the next wimp null poll. That’s how I did it, and it worked at the time. I think the important bit in doing a double click is the “button released” mouse events. In fact, here’s a little BASIC proglet to simulate a double-select click at the current mouse position:DIM block% 9 SYS"OS_Mouse" TO x%,y%,,t% PROCevent(x%, y%, %100, t%) PROCevent(x%, y%, %000, t%) PROCevent(x%, y%, %100, t%) PROCevent(x%, y%, %000, t%) END DEFPROCevent(x%, y%, b%, t%) block%!0 = (x% AND &ffff) block%!2 = (y% AND &ffff) block%?4 = b% block%!5 = t% SYS"OS_IntOff" FOR i% = 0 TO 8 SYS"XOS_Byte",138,9,block%?i% NEXT SYS"XOS_IntOn" ENDPROC |
Andrew Conroy (370) 740 posts |
Ah, that may be where I was going wrong. I need to send a ‘button down’ each time the mouse moves whilst the botton is held down, rather than simply sending a ‘button down’ when it’s first held down and then a ‘button released’ when it’s released. I’m playing around with a mouse replacement, so this would be working in ‘real-time’ rather than replaying recorded events. I shall demo what I’ve got at SAUG tonight, provided we don’t decide to go and riot in Southampton city centre instead :-) |