0

我需要一些帮助来隐藏和禁用鼠标指针。但我需要将所有鼠标事件发送到其他设备。所以主要场景是:打开SWT应用程序-->按下按钮(或标签,或者你想要的......)-->鼠标SWT端消失,没有指针,没有事件-->鼠标指针出现在其他设备上-- > 我可以从主物理鼠标控制其他设备的鼠标指针。

我现在发现的是如何使指针透明,我想到了可以每 20 毫秒修复一次位置的计时器。但是我怎样才能防止事件发生呢?我还能抓到他们吗?

问候

更新:

最终解决方案:新的全屏窗口半透明

public class AntiMouseGui {

    Display display;
    Shell shell;

    final int time = 20;

    private Runnable timer = null;

    public AntiMouseGui(final Display display, final DebugForm df, final PrintWriter socketOut) {

        Image bg = new Image(display, "icons/hide_mouse_wallpapaer.png");

        shell = new Shell(display, SWT.NO_TRIM | SWT.ON_TOP);

        final int dis_x = display.getClientArea().width, dis_y = display.getClientArea().height;
        shell.setSize(dis_x, dis_y);

        shell.setBackgroundImage(bg);
        shell.setAlpha(50);
        shell.setMinimumSize(shell.getSize()); 
        shell.open();


        timer = new Runnable() {
            public void run() {
                Point cur_loc = display.getCursorLocation();
                int span_x = dis_x / 2 - cur_loc.x, span_y = dis_y / 2 - cur_loc.y;

                df.appendTxt("span x = " + span_x + " span y = " + span_y);
                if (span_x != 0) Controller.moveMouseRight(socketOut, -span_x);
                if (span_y != 0) Controller.moveMouseDown(socketOut, -span_y);

                display.setCursorLocation(new Point(dis_x / 2, dis_y / 2));
                if (!shell.isDisposed()) display.timerExec(time, this);
            }
        };
        display.timerExec(time, timer);

    }

}
4

1 回答 1

0

您可以创建一个Shell全屏并将其 alpha 值设置为 0。然后只需将 a 添加ListenerDisplay并捕获所有鼠标事件:

public static void main(String[] args) {
    final Display display = new Display();
    final Shell shell = new Shell(display);
    shell.setLayout(new FillLayout());

    shell.setFullScreen(true);
    shell.setAlpha(0);

    final Listener sendSomewhere = new Listener() {

        @Override
        public void handleEvent(Event event) {
            int x = event.x;
            int y = event.y;

            int eventType = event.type;

            System.out.println(x + " " + y + ": " + eventType);

            // send the coordinates to your other device
        }
    };

    int[] events = new int[] {SWT.MouseDown, SWT.MouseUp, SWT.MouseDoubleClick, SWT.Selection};

    for(int event : events)
    {
        display.addFilter(event, sendSomewhere);
    }


    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch()) {
            display.sleep();
        }
    }
    display.dispose();
}

只需使用Alt+Tab即可返回上一个窗口。

于 2012-10-12T14:20:29.480 回答