Move mouse position (Win 10 64bit)/Prevent screen sleep

Hi,
First post in the Windows part of the forum :wink:

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 :wink:

#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”.

If you use MBS Plugins, check the RemoteControlMBS for such commands.

[quote=383284:@Albin Kiland]Hi,
First post in the Windows part of the forum :wink:

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 :wink:

#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.

Thanks for your suggestions! I’ll try them out and get back to you :slight_smile:

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:@JulianS]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 :confused:

Top of my head: (untested)

[code]
Declare Function SetThreadExecutionState Lib “Kernel32” (state as uint32) as unint32

//stop sleep
oldstate = SetThreadExecutionState (&H80000003)[/code]

//set it back

call SetThreadExecutionState  (oldstate )

Hmmm, odd, are you testing the code via Remote Desktop or another screen sharing system or are you logged into the local machine?

Remote Desktop. Now when you mention it, that might have something to do with it…
I’m gonna give Jeffs suggestion a go too :slight_smile:

[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:@JulianS]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 Julian and Michel!
Im teting out the SetThreadExecutionState right now. If that still doesn’t do it. I’ll revisit the move cursor approach :slight_smile:

Maybe you need to work with the DPMS.

On https://forum.xda-developers.com/showthread.php?t=445700 i found:

Declare Sub IdleTimerReset Lib "coredll.dll" Alias "SystemIdleTimerReset" ()

Did you already try this? :slight_smile:

#if TargetWin32
Declare function SetThreadExecutionState Lib “kernel32” (ByVal esFlags as UInt32) as UInt32

const ES_AWAYMODE_REQUIRED = &h40
const ES_DISPLAY_REQUIRED = &h2
const ES_SYSTEM_REQUIRED = &h1
const ES_CONTINUOUS = &h80000000
const ES_USER_PRESENT = &h4

dim result as UInt32
result = SetThreadExecutionState(ES_SYSTEM_REQUIRED or ES_DISPLAY_REQUIRED)

#else TargetMacOS
Declare Function UpdateSystemActivity Lib “CoreServices” (activity As UInt8) As Int16
Const UsrActivity = 1

Call UpdateSystemActivity(UsrActivity)

#endif

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!

[quote=383299:@Jeff Tullin]“TargetWin32” is only for 32bit

That’s not true.
It returns true for all styles of Windows.[/quote]

For now.
TargetWin32 is deprecated in 2018r1, in favor of TargetWindows

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.