Java的:保持光标在一个区域 [英] Java: Holding the cursor in an area

查看:240
本文介绍了Java的:保持光标在一个区域的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于那些你们谁发挥疯狂互动,最令人沮丧的事情之一是,当光标离开比赛区域,你不小心点击。这导致游戏散焦和在几秒钟内你的角色死亡。为了解决这个问题,我想使我可以在将持有光标在屏幕里面,直到我preSS的关键,像ESC什么后台运行Java应用程序。

For those of you who have played Madness Interactive, one of the most frustrating things is when the cursor leaves the game area, and you accidentally click. This causes the game to defocus and your character dies in a matter of seconds. To fix this, I'd like to make a java application that I can run in the background that will hold the cursor inside the screen until I press a key, like ESC or something.

我看到这个实施两种方式,但我不知道,如果其中任何一个都是可行的。

I see two ways of implementing this, but I don't know if either of them are workable.


  1. 请即疯狂互动的呈现区域的大小相匹配的AWT框架,并使用控制光标。

  2. 使用一些外的情况下操作系统调用,使光标在给定的区域。

的方法#1优势:更容易实现框架的调整大小,使得用户可以看到封闭区域的形状和位置

Advantage of approach #1: Much easier to implement resizing of the frame so that user can see the shape and position of the enclosed area.

与方法1的潜在问题:AWT框架可能会需要从游戏中运行浏览器窗口中窃取焦点,使得整个解决方案毫无意义的。

Potential Problems with approach #1: The AWT Frame would likely need to steal focus from the browser window the game is running in, making the whole solution pointless.

我的问题是,这两种方法可行?如果没有,是否有一个可行的选择?

My question is, are either of these approaches viable? If not, is there a viable option?

编辑:我很愿意在必要

EDIT2:我可能会发展为这个浏览器插件,但我从来没有做过那样的发展。我会研究它。

I might develop a browser plugin for this, but I've never done that kind of development before. I'll research it.

推荐答案

如果这是一个基于浏览器的游戏,考虑写一个Greasemonkey的脚本,它作为一个浏览器扩展,可以进行筛选,仅在游戏的网站上运行

If this is for a browser-based game, consider writing a greasemonkey script, which acts as a browser extension that can be filtered to only run on the game's site.

在最简单的例子,假设可点击的区域是(0,0) - (300,400),那么你可以在下面的事件处理程序添加到网页:

In the simplest case, assume the clickable regions are (0,0) - (300,400), then you can add the following event handler to the page:

$(document).on('click', function(event) {
  if (event.pageX > 300 || event.pageY > 400) {
    return false;
  }
});

您可以进一步细化你的脚本执行以下操作:

You can further refine your script to do the following:


  1. 调整浏览器是完美的尺寸为玩游戏

  2. 而不是检查绝对X,点击的ŸCOORDS,检查它是否是你不想收到点击页面的元素中

  3. 添加自定义键绑定到乌姆..帮你在游戏

  4. 编写JavaScript机器人,可以玩游戏本身

这篇关于Java的:保持光标在一个区域的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆