[Lazarus] MouseAndKeyInput package and scroll up/down with whell button

silvioprog silvioprog at gmail.com
Sun Jan 17 04:37:07 CET 2016


Hello,

First, thanks to Tom Gregorovic for sharing this awesome package! :-)

So, I think that MouseAndKeyInput package should implement the scroll
support (triggered via up/down whell button).

I took a look at its code, and it seems implemented to compile on Linux,
Mac OS and Windows. Nice! :-) I can help to implement the scroll method for
Linux and Windows, because I don't have Mac OS here, but I believe that can
be easily implemented too.

On Windows the packed uses the Windows API, declaring the JwaWinUser unit,
so, I did a small test in a console program and the scrolling draft worked
fine here in my Windows 7 and 10:

=== begin code ===

program project1;

uses JwaWindows;

{  mouseData:
    . enable the global scrolling (nil for local scrolling)
    . up: WHEEL_DELTA
    . down: dword(-WHEEL_DELTA) }

var VInput: TInput;
begin
  VInput := Default(TInput); // good bye FillChar :-)
  VInput.type_ := INPUT_MOUSE;
  VInput.mi.dwFlags := MOUSEEVENTF_WHEEL;
  VInput.mi.mouseData := WHEEL_DELTA;
  while True do begin
    SendInput(1, @VInput, SizeOf(VInput));
    Sleep(1000);
  end;
end.

=== end code ===

It's very easy to test it, just compile and run the project above and set
the SO cursor in a window with the vertical scroll enabled that the magic
happens. The WHEEL_DELTA flag allows this project to scroll any window.

On Linux the package uses the libXtst, that is very easy to implement the
scrolling feature too, we just:

=== begin code ===

// Ubuntu users: perform the `# ln -s
/usr/lib/x86_64-linux-gnu/libXtst.so.6 /usr/lib/libXtst.so` and check if
the Xtst link was created.

program project1;

{$linklib Xtst}

uses xlib, sysutils;

{ button:
    . up: 4
    . down: 5 }

// it just a test, the XTestFakeButtonEvent is already declared in the
MouseAndKeyInput package hehe :-)
function XTestFakeButtonEvent(dpy: PDisplay; button: dword;
  is_press: Boolean; delay: dword): longint; cdecl; external;

var  VDisplay: PDisplay;
begin
  VDisplay := XOpenDisplay(nil);
  while True do begin
    // I got this idea from the Linux `xte` command line tool [1]
    XTestFakeButtonEvent(VDisplay, 5, True, 0);
    XTestFakeButtonEvent(VDisplay, 5, False, 0);
    XSync(VDisplay, 0);
    Sleep(1000);
  end;
  XCloseDisplay(VDisplay);
end.

=== end code ===

It's same to perform `$ while true; do xte 'mouseclick 5'; sleep 2; done`.

I don't know it the MouseAndKeyInput depends on LCL, if so I think that it
should be implemented depending only FCL, allowing the package to be used
in daemon programs (e.g as a micro vnc service).


[1] xte.c
...
218. void mouse_click( Display *d, XDevice *device, int button ) {
219.     dmsg( 1, "Clicking mouse button %d\n", button );
*220.     xte_FakeButtonEvent( d, device, button, True, CurrentTime );*
*221.     xte_FakeButtonEvent( d, device, button, False, CurrentTime );*
222. }
...

-- 
Silvio Clécio
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus-ide.org/pipermail/lazarus/attachments/20160117/723b257b/attachment-0002.html>


More information about the Lazarus mailing list