Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions contrib/platform/src/com/sun/jna/platform/win32/User32.java
Original file line number Diff line number Diff line change
Expand Up @@ -2326,6 +2326,21 @@ LRESULT SendMessageTimeout(HWND hWnd, int msg, WPARAM wParam, LPARAM lParam,
* Returns nonzero if successful or zero otherwise. To get extended
* error information, call GetLastError.
*/
boolean SetCursorPos(int x, int y);

/**
* Moves the cursor to the specified screen coordinates.
*
* @param x
* The new x-coordinate of the cursor.
* @param y
* The new y-coordinate of the cursor.
* @return Whether the call succeeded.
* @deprecated Windows expects 32-bit coordinates, so this declaration has
* the wrong calling convention on 32-bit Windows. Use
* {@link #SetCursorPos(int, int)} instead.
*/
@Deprecated
boolean SetCursorPos(long x, long y);

/**
Expand Down
10 changes: 10 additions & 0 deletions contrib/platform/test/com/sun/jna/platform/win32/User32Test.java
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,14 @@ public void testGetCursorPos() {
assertTrue("Y coordinate in POINT should be >= 0", cursorPos.y >= 0);
}

@Test
public void testSetCursorPosNativeSignature() throws NoSuchMethodException {
assertEquals(boolean.class,
User32.class.getMethod("SetCursorPos", int.class, int.class).getReturnType());
assertTrue(User32.class.getMethod("SetCursorPos", long.class, long.class)
.isAnnotationPresent(Deprecated.class));
}

@Test
public void testSetCursorPos() {
POINT cursorPos = new POINT();
Expand All @@ -432,6 +440,8 @@ public void testSetCursorPos() {
),
cursorPos2.x == cursorPos.x + 20
);
assertEquals("Y coordinate should be preserved after SetCursorPos",
cursorPos.y, cursorPos2.y);
}

@Test
Expand Down