简体   繁体   English

java.awt.Robot:如何将鼠标/键盘事件发送到特定窗口? 有跨平台支持?

[英]java.awt.Robot: how to send mouse/keyboard events to a specific window? with cross-platform support?

So from this question In Java Swing how do you get a Win32 window handle (hwnd) reference to a window? 因此,从这个问题中,您如何在Java Swing中获得对窗口的Win32窗口句柄(hwnd)引用? it appears that I can get the window32 handle . 看来我可以得到window32句柄。 would it be possible for java.awt.Robot to send mouse/keyboard events to that window handle? java.awt.Robot是否有可能将鼠标/键盘事件发送到该窗口句柄?

sometimes when I am sending keys via Robot, if the window gets minimized, it will start typing into other background irrelevant windows that are open. 有时,当我通过机器人发送密钥时,如果窗口最小化,它将开始键入其他打开的与背景无关的窗口。 I want to prevent this by allowing Robot to send keys and mouse events to that specific window of interest. 我想通过允许机器人将键和鼠标事件发送到感兴趣的特定窗口来防止这种情况。

Would it be possible to achieve the same deal in Mac and Linux as well? 在Mac和Linux中是否也可以实现相同的交易? be able to send Robot events to those respective specific window handles? 能够将机器人事件发送到相应的特定窗口句柄?

This is a classic problem with Robot. 这是机器人的经典问题。 As they have quoted in the other thread, its not possible with pure AWT/Swing. 正如他们在另一个线程中引用的那样,纯AWT / Swing无法实现。 You have to get into sun's internal API or use native code. 您必须使用sun的内部API或使用本机代码。 There is not getting around that problem. 没有解决这个问题。

It is exactly because of the problem that you have ie make it work across OS's is why Java has not exposed such a control. 正是由于您遇到的问题(即使其在整个OS上运行)才是Java尚未公开此类控件的原因。

It would be useful to know what you are using this for. 了解您将其用于什么将很有用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM