Reputation: 546
How can i get the current mouse cursor type using windows API in java ? (Cursor type means : pointer, text cursor , busy cursor and the rest of the categories)
I've found a link Here
where the api is given as
BOOL WINAPI GetCursorInfo(
__inout PCURSORINFO pci
);
But how to use the api in java
Upvotes: 1
Views: 2908
Reputation: 5003
This works quite well for me on Win7. The script is in Python but should be easy enough to translate into any other language. Of course, it only works if the respective application isn't using custom cursors:
from win32con import IDC_APPSTARTING, IDC_ARROW, IDC_CROSS, IDC_HAND, \
IDC_HELP, IDC_IBEAM, IDC_ICON, IDC_NO, IDC_SIZE, IDC_SIZEALL, \
IDC_SIZENESW, IDC_SIZENS, IDC_SIZENWSE, IDC_SIZEWE, IDC_UPARROW, IDC_WAIT
from win32gui import LoadCursor, GetCursorInfo
def get_current_cursor():
curr_cursor_handle = GetCursorInfo()[1]
return Cursor.from_handle(curr_cursor_handle)
class Cursor(object):
@classmethod
def from_handle(cls, handle):
for cursor in DEFAULT_CURSORS:
if cursor.handle == handle:
return cursor
return cls(handle=handle)
def __init__(self, cursor_type=None, handle=None):
if handle is None:
handle = LoadCursor(0, cursor_type)
self.type = cursor_type
self.handle = handle
DEFAULT_CURSORS \
= APPSTARTING, ARROW, CROSS, HAND, HELP, IBEAM, ICON, NO, SIZE, SIZEALL, \
SIZENESW, SIZENS, SIZENWSE, SIZEWE, UPARROW, WAIT \
= Cursor(IDC_APPSTARTING), Cursor(IDC_ARROW), Cursor(IDC_CROSS), \
Cursor(IDC_HAND), Cursor(IDC_HELP), Cursor(IDC_IBEAM), Cursor(IDC_ICON), \
Cursor(IDC_NO), Cursor(IDC_SIZE), Cursor(IDC_SIZEALL), \
Cursor(IDC_SIZENESW), Cursor(IDC_SIZENS), Cursor(IDC_SIZENWSE), \
Cursor(IDC_SIZEWE), Cursor(IDC_UPARROW), Cursor(IDC_WAIT)
Upvotes: 0
Reputation: 35011
I think the closest you're going to get is thru:
Upvotes: 2
Reputation: 1
You can use JNA - java native access. It provides access to native libraries, like DLL in windows. https://github.com/twall/jna#readme
Upvotes: 0