Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/389.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java SWT和完全禁用并隐藏鼠标指针_Java_Events_Cursor_Swt_Hide - Fatal编程技术网

Java SWT和完全禁用并隐藏鼠标指针

Java SWT和完全禁用并隐藏鼠标指针,java,events,cursor,swt,hide,Java,Events,Cursor,Swt,Hide,我需要一些帮助来隐藏和禁用鼠标指针。但我需要将所有鼠标事件发送到其他设备。 所以,主要场景是:打开SWT应用程序-->按下按钮(或标签,或您想要的…)-->鼠标SWT侧消失,没有指针,没有事件-->鼠标指针出现在其他设备-->我可以从主鼠标控制其他设备的鼠标指针 我现在发现的是如何使指针透明,我想到了一个计时器,它可以每20毫秒固定一个位置。但我如何才能防止事件发生?我还能抓住他们吗 问候 更新: 最终解决方案:全新全屏半透明窗口 public class AntiMouseGui {

我需要一些帮助来隐藏和禁用鼠标指针。但我需要将所有鼠标事件发送到其他设备。 所以,主要场景是:打开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);

    }

}

您可以创建一个全屏的
Shell
,并将其alpha值设置为0。然后只需将一个
监听器添加到
显示中
,并捕获所有鼠标事件:

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返回上一个窗口。

请详细说明。很难说这里到底要问什么。我的意思是我需要捕捉鼠标事件并将它们发送到其他设备从何处捕捉它们并将它们发送到何处?从桌面端捕捉并发送到Android端。我不需要在桌面端对事件产生任何影响。你的问题并没有提到任何关于android的问题。应用程序如何连接,即SWT部分和android部分如何通信?此代码防止仅在SWT中捕获。但我需要一个“遥控式”,在这里你不能在本地做任何事情。类似这样:@user1417608这不能用Java完成,因为Java只能控制窗口内的内容。也许JNI是可能的。我正在寻找一个打开全屏透明窗口的解决方案。如果我达到透明功能,可能会工作。@user1417608查看编辑的答案。请尽可能多地在问题中添加相关细节。那样我就能更快地帮助你了。