I asked the question if I were able to write an app that simply moves the mouse cursor to 0, 0 on Windows 10 64bit.
I found a function from @Michel Bujardet but it does not seem to do anything, at least not on Win 10 64bit.
Any ideas? I think it was for a touch screen that insists on going into sleep mode, and moving the mouse might prevent that.
Noooot a windows guy here
#if TargetWin32
Declare Function SetCursorPos Lib "user32" (ByVal x As Integer, ByVal y As Integer) As Integer
//==========================================
// Set cursor position to top left of screen
//==========================================
call SetCursorPos(0,0)
#endif
You should use âif TargetWindowsâ. âTargetWin32â is only for 32bit. If have checked it with Window7 64Bit and it works. I hope library âuser32â is available on Window10. if not, try âuser64â or âuserâ.
[quote=383284:@Albin Kiland]Hi,
First post in the Windows part of the forum
I asked the question if I were able to write an app that simply moves the mouse cursor to 0, 0 on Windows 10 64bit.
I found a function from @Michel Bujardet but it does not seem to do anything, at least not on Win 10 64bit.
Any ideas? I think it was for a touch screen that insists on going into sleep mode, and moving the mouse might prevent that.
Noooot a windows guy here
#if TargetWin32
Declare Function SetCursorPos Lib "user32" (ByVal x As Integer, ByVal y As Integer) As Integer
//==========================================
// Set cursor position to top left of screen
//==========================================
call SetCursorPos(0,0)
#endif[/quote]
You want to use Int32, since I believe Integer in 64 bit is Int64.
Thatâs not true.
It returns true for all styles of Windows.
USER32 is the right name for both 32 and 64bit versions.
The name user32.dll is misleading. Itâs a 64 bit user32.dll youâre calling.
The 64 bit version is located at %windir%\System32\user32.dll.
A 32-bit version is included for compatibility with 32-bit applications. Itâs located at %windir%\SysWOW64\user32.dll
The Windows Dev Center reference says âThe cursor is a shared resource. A window should move the cursor only when the cursor is in the windowâs client area.â
But I suspect it is the mouse system events that keep the machine awake, not the actual position of the mouse pointer.
Perhaps SetThreadExecutionState is a better bet?
Thats in Kernel32
[quote=383299:@Jeff Tullin]Thatâs not true.
It returns true for all styles of Windows.
USER32 is the right name for both 32 and 64bit versions.
The name user32.dll is misleading. Itâs a 64 bit user32.dll youâre calling.
The 64 bit version is located at %windir%\System32\user32.dll.
A 32-bit version is included for compatibility with 32-bit applications. Itâs located at %windir%\SysWOW64\user32.dll
The Windows Dev Center reference says âThe cursor is a shared resource. A window should move the cursor only when the cursor is in the windowâs client area.â
But I suspect it is the mouse system events that keep the machine awake, not the actual position of the mouse pointer.
Perhaps SetThreadExecutionState is a better bet?
Thats in Kernel32[/quote]
Thanks. By the looks of it, SetThreadExecutionState might be what I want to use.
To a declare(and windows) newbie, any pointers in the right direction?
As Michel mentioned, this should work, Iâve just tested it here, doesnât it work for you or does it move the mouse but it doesnât keep the device awake? However, calling SetTheadExecutionState would be the correct way to keep the device awake.
Declare Function SetCursorPos Lib "User32" (x As Int32, y As Int32) As Int32
Call SetCursorPos(0, 0)
[quote=383305:@]Declare Function SetCursorPos Lib âUser32â (x As Int32, y As Int32) As Int32
Call SetCursorPos(0, 0)[/quote]
Nope. Tried exactly that in PushButton but the cursor stays in place wierd
[quote=383315:@Albin Kiland]Remote Desktop. Now when you mention it, that might have something to do with itÂ
Iâm gonna give Jeffs suggestion a go too :)[/quote]
Ah yes, you need to call OpenInputDesktop and SetThreadDesktop if youâre not on the main desktop, otherwise your SetCursorPos is moving the mouse on the main login.
[quote=383305:@]As Michel mentioned, this should work, Iâve just tested it here, doesnât it work for you or does it move the mouse but it doesnât keep the device awake? However, calling SetTheadExecutionState would be the correct way to keep the device awake.
Declare Function SetCursorPos Lib "User32" (x As Int32, y As Int32) As Int32
Call SetCursorPos(0, 0)[/quote]
It works like clockworks in a button under Windows 10 64 bit, 64 bit app.
Thanks Connor,
Something came up so Iâll have to continue on this later this week or the next.
Thanks everyone who have contributed with their time on this so far!
It should be noted that moving the cursor like that is kind of rude to the user, and may give the impression that something is wrong with the mouse or the system.
Do it only if there is no other way, and if possible, let the user know ahead of time.