- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
SOVED 感谢@deFreitas
我正在尝试用java
创建远程控制程序。我的问题是我使用机器人类的屏幕截图从远程计算机获取图像,因此我看不到远程光标。我知道我可以在屏幕截图上绘制光标图像,但如何获取全局光标类型。
我已经搜索了很多,我得到的最接近的是这段代码:
public interface User32 extends com.sun.jna.Library {
public static User32 INSTANCE = (User32) com.sun.jna.Native
.loadLibrary("User32", User33.class);
public com.sun.jna.platform.win32.WinDef.HCURSOR GetCursor();
}
但我不明白如何从 HCursor
类获取光标类型...有没有办法获取类型甚至光标位图??
编辑:我发现了这个功能:
WinNT.HANDLE LoadImage(WinDef.HINSTANCE hinst,
String name,
int type,
int xDesired,
int yDesired,
int load)
但我不知道该给它哪种类型。我看到的每个网站都会加载图像或特定的光标类型......
最佳答案
有可能,基本上你需要GetCursorInfo和 LoadImage
BOOL GetCursorInfo(PCURSORINFO pci)
它获取当前光标句柄并将其存储在PCURSORINFO.hCursor
中,这是实际的光标,但没有指示符可以知道它是什么类型,请注意,它是Windows而不是JNA限制。无论如何,如果你使用
HANDLE WINAPI LoadImage(...,PCTSTR cursorId,...)
它将返回一个给定游标类型 ID 的句柄 here a list以及所有可用的游标 ID。这样你就可以使用LoadImage
加载所有游标,然后只需对GetCursorInfo
结果进行等于,匹配的结果就是实际的游标类型。这是一个使用 JNA 的工作 JAVA 程序
import com.sun.jna.Memory;
import com.sun.jna.Native;
import com.sun.jna.Pointer;
import com.sun.jna.Structure;
import com.sun.jna.platform.win32.*;
import java.io.IOException;
import java.util.*;
/**
* https://msdn.microsoft.com/pt-br/library/windows/desktop/ms648029(v=vs.85).aspx
* Test cursors - https://developer.mozilla.org/en-US/docs/Web/CSS/cursor
* Chromium cursor map - https://github.com/mageddo/chromium/blob/master/webkit/glue/webcursor_win.cc
* Load icon example - https://github.com/java-native-access/jna/blob/master/contrib/platform/test/com/sun/jna/platform/win32/GDI32Test.java#L54
* understanding makeintresource - https://stackoverflow.com/questions/3610565/why-does-makeintresource-work
* all possible windows error codes - https://msdn.microsoft.com/en-us/library/windows/desktop/ms681386(v=vs.85).aspx
* Cursor ids - https://msdn.microsoft.com/en-us/library/windows/desktop/ms648391(v=vs.85).aspx
*
*/
public class Main {
public static void main(String[] args) throws Exception {
while(true){
final Main main = new Main();
System.out.println(main.getCurrentCursor());
Thread.sleep(2000);
}
}
private final Map<WinNT.HANDLE, Cursor> cursors;
private final User32 user32;
public Main(){
user32 = User32.INSTANCE;
cursors = loadCursors();
}
/**
* Load all possible cursors to a map
*/
private Map<WinNT.HANDLE, Cursor> loadCursors() {
final Map<WinNT.HANDLE, Cursor> cursors = new HashMap<>();
for (final Cursor cursor : Cursor.values()) {
final Memory memory = new Memory(Native.getNativeSize(Long.class, null));
memory.setLong(0, cursor.getCode());
final Pointer resource = memory.getPointer(0);
final WinNT.HANDLE hcursor = this.user32.LoadImageA(
null, resource, WinUser.IMAGE_CURSOR, 0, 0, WinUser.LR_SHARED
);
if(hcursor == null || Native.getLastError() != 0){
throw new Error("Cursor could not be loaded: " + String.valueOf(Native.getLastError()));
}
cursors.put(hcursor, cursor);
}
return Collections.unmodifiableMap(cursors);
}
public Cursor getCurrentCursor(){
final CURSORINFO cursorinfo = new CURSORINFO();
final int success = this.user32.GetCursorInfo(cursorinfo);
if(success != 1){
throw new Error("Could not retrieve cursor info: " + String.valueOf(Native.getLastError()));
}
// you can use the address printed here to map the others cursors like ALL_SCROLL
System.out.printf("currentPointer=%s%n", cursorinfo.hCursor);
// some times cursor can be hidden, in this case it will be null
if(cursorinfo.hCursor != null && cursors.containsKey(cursorinfo.hCursor)){
return cursors.get(cursorinfo.hCursor);
}
return null;
}
// typedef struct {
// DWORD cbSize;
// DWORD flags;
// HCURSOR hCursor;
// POINT ptScreenPos;
// } CURSORINFO, *PCURSORINFO, *LPCURSORINFO;
public static class CURSORINFO extends Structure {
public int cbSize;
public int flags;
public WinDef.HCURSOR hCursor;
public WinDef.POINT ptScreenPos;
public CURSORINFO() {
this.cbSize = Native.getNativeSize(CURSORINFO.class, null);
}
@Override
protected List<String> getFieldOrder() {
return Arrays.asList("cbSize", "flags", "hCursor", "ptScreenPos");
}
}
public interface User32 extends com.sun.jna.Library {
User32 INSTANCE = Native.loadLibrary("User32.dll", User32.class);
// BOOL WINAPI GetCursorInfo(
// _Inout_ PCURSORINFO pci
// );
int GetCursorInfo(CURSORINFO cursorinfo);
// HANDLE WINAPI LoadImage(
// _In_opt_ HINSTANCE hinst,
// _In_ LPCTSTR lpszName,
// _In_ UINT uType,
// _In_ int cxDesired,
// _In_ int cyDesired,
// _In_ UINT fuLoad
// );
WinNT.HANDLE LoadImageA(
WinDef.HINSTANCE hinst,
Pointer lpszName,
int uType,
int cxDesired,
int cyDesired,
int fuLoad
);
}
public enum Cursor {
APPSTARTING(32650),
NORMAL(32512),
CROSS(32515),
HAND(32649),
HELP(32651),
IBEAM(32513),
NO(32648),
SIZEALL(32646),
SIZENESW(32643),
SIZENS(32645),
SIZENWSE(32642),
SIZEWE(32644),
UP(32516),
WAIT(32514),
PEN(32631)
;
private final int code;
Cursor(final int code) {
this.code = code;
}
public int getCode() {
return code;
}
}
}
Obs:并非所有可能的光标都有可用的资源ID(如放大、缩小),这是因为系统默认光标为15,其他都是由软件(如chrome)创建的自定义光标、firefox)这样windows就无法识别它是什么类型的光标。
Jna版本
compile group: 'net.java.dev.jna', name: 'jna', version: '4.5.0'
compile group: 'net.java.dev.jna', name: 'jna-platform', version: '4.5.0'
关于java - java中使用jna获取鼠标类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47634213/
我需要将文本放在 中在一个 Div 中,在另一个 Div 中,在另一个 Div 中。所以这是它的样子: #document Change PIN
奇怪的事情发生了。 我有一个基本的 html 代码。 html,头部, body 。(因为我收到了一些反对票,这里是完整的代码) 这是我的CSS: html { backgroun
我正在尝试将 Assets 中的一组图像加载到 UICollectionview 中存在的 ImageView 中,但每当我运行应用程序时它都会显示错误。而且也没有显示图像。 我在ViewDidLoa
我需要根据带参数的 perl 脚本的输出更改一些环境变量。在 tcsh 中,我可以使用别名命令来评估 perl 脚本的输出。 tcsh: alias setsdk 'eval `/localhome/
我使用 Windows 身份验证创建了一个新的 Blazor(服务器端)应用程序,并使用 IIS Express 运行它。它将显示一条消息“Hello Domain\User!”来自右上方的以下 Ra
这是我的方法 void login(Event event);我想知道 Kotlin 中应该如何 最佳答案 在 Kotlin 中通配符运算符是 * 。它指示编译器它是未知的,但一旦知道,就不会有其他类
看下面的代码 for story in book if story.title.length < 140 - var story
我正在尝试用 C 语言学习字符串处理。我写了一个程序,它存储了一些音乐轨道,并帮助用户检查他/她想到的歌曲是否存在于存储的轨道中。这是通过要求用户输入一串字符来完成的。然后程序使用 strstr()
我正在学习 sscanf 并遇到如下格式字符串: sscanf("%[^:]:%[^*=]%*[*=]%n",a,b,&c); 我理解 %[^:] 部分意味着扫描直到遇到 ':' 并将其分配给 a。:
def char_check(x,y): if (str(x) in y or x.find(y) > -1) or (str(y) in x or y.find(x) > -1):
我有一种情况,我想将文本文件中的现有行包含到一个新 block 中。 line 1 line 2 line in block line 3 line 4 应该变成 line 1 line 2 line
我有一个新项目,我正在尝试设置 Django 调试工具栏。首先,我尝试了快速设置,它只涉及将 'debug_toolbar' 添加到我的已安装应用程序列表中。有了这个,当我转到我的根 URL 时,调试
在 Matlab 中,如果我有一个函数 f,例如签名是 f(a,b,c),我可以创建一个只有一个变量 b 的函数,它将使用固定的 a=a1 和 c=c1 调用 f: g = @(b) f(a1, b,
我不明白为什么 ForEach 中的元素之间有多余的垂直间距在 VStack 里面在 ScrollView 里面使用 GeometryReader 时渲染自定义水平分隔线。 Scrol
我想知道,是否有关于何时使用 session 和 cookie 的指南或最佳实践? 什么应该和什么不应该存储在其中?谢谢! 最佳答案 这些文档很好地了解了 session cookie 的安全问题以及
我在 scipy/numpy 中有一个 Nx3 矩阵,我想用它制作一个 3 维条形图,其中 X 轴和 Y 轴由矩阵的第一列和第二列的值、高度确定每个条形的 是矩阵中的第三列,条形的数量由 N 确定。
假设我用两种不同的方式初始化信号量 sem_init(&randomsem,0,1) sem_init(&randomsem,0,0) 现在, sem_wait(&randomsem) 在这两种情况下
我怀疑该值如何存储在“WORD”中,因为 PStr 包含实际输出。? 既然Pstr中存储的是小写到大写的字母,那么在printf中如何将其给出为“WORD”。有人可以吗?解释一下? #include
我有一个 3x3 数组: var my_array = [[0,1,2], [3,4,5], [6,7,8]]; 并想获得它的第一个 2
我意识到您可以使用如下方式轻松检查焦点: var hasFocus = true; $(window).blur(function(){ hasFocus = false; }); $(win
我是一名优秀的程序员,十分优秀!