2012-10-12 25 views
0

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

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

问候

更新:

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

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); 

    } 

} 
+0

请详细说明。很难说这里到底在问什么。 – Baz

+0

我的意思是我需要捕获鼠标事件并将它们发送到其他设备 – user1417608

+0

从哪里抓住它们并将它们发送到哪里? – Baz

回答

0

您可以创建一个Shell是全屏,并设置它的alpha值设置为0。然后,只需在Display中添加Listener并捕获所有鼠标事件:

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 + 选项卡返回到上一个窗口。

+0

此代码防止仅在SWT中捕获。但是我需要一种“遥控风格”,你不能在当地做任何事情。像这样:http://synergy-foss.org/ – user1417608

+0

@ user1417608这不能用Java来完成,因为Java只能控制窗口内的东西。也许这是可能的与JNI。 – Baz

+0

我正在寻找解决方案,打开全屏透明窗口。如果我达到透明功能可能会起作用。 – user1417608