java 光标在文本框中,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.

Make an AWT frame that matches the size of Madness Interactive's render area, and control the cursor using that.

Use some out-of-context operating system calls to keep the cursor in a given area.

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.

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?

EDIT: I am willing to use another programming language if necessary.

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

解决方案

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.

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:

resize the browser to be the perfect size for playing the game

instead of checking the absolute x,y coords of the click, check if it is inside an element of the page that you don't want to receive the click

add custom key bindings to umm.. help you at the game

write a javascript bot that can play the game itself

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值