我需要一些帮助来隐藏和禁用鼠标指针。但我需要将所有鼠标事件发送到其他设备。 所以主要场景是:打开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 :(得分:0)
您可以创建一个全屏Shell
并将其alpha值设置为0.然后只需将Listener
添加到Display
并捕获所有鼠标事件:
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 + 标签即可返回上一个窗口。