setcursorpos() not working on y axis.

medic5678

Board Regular
Joined
Nov 13, 2018
Messages
67
this should be pretty simple.

Declare PtrSafe Function SetCursorPos Lib "user32" (ByVal x As Long, ByVal y As Long) As Long

I was capturing the mouse position with GetCursorPos, and I noticed that it would always treat the y value as zero.

So I put in manual coordinates, and it still does the same thing.

Sub Setcursor()


SetCursorPos 300, 100


End Sub

whatever I change the x value to (first value) works fine going across the screen horizontally. Vertically, any number I put in is treated as 0.

I'm using this in a userform.
 
Last edited:
Use LongPtr for pointers and handles

The co-ordinates are neither, they're just values, which is why they should remain as Long. If you look at Microsoft's API documentation for 64bit, you'll see the declaration is the same as originally posted. ;)
 
Last edited:
Upvote 0

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.
The co-ordinates are neither, they're just values, which is why they should remain as Long. If you look at Microsoft's API documentation for 64bit, you'll see the declaration is the same as originally posted
@RoryA
All that I see is fog!
Is there something simple somewhere that explains the logic behind the 64bit vs 32bit declarations
Various other threads seem to have been "leading me up the garden path"!
When should LongPtr be used?
 
Upvote 0
Thanks @RoryA
Microsoft File downloaded and installed - how do I now look at it? :confused:
 
Upvote 0
In your C drive you should see a new folder called Office 2010 Developer Resources. Look in there under Documents\Office2010Win32API_PtrSafe and you should see three files in different formats. I use the Win32API_PtrSafe.TXT one.
 
Upvote 0
@RoryA Got it. Thanks for new reading material for a long winter night!
(y)(y)
 
Upvote 0
It’ll help you sleep if nothing else... ;)
 
Upvote 0
Created another project and form with label. Clicking on a control and running setcursorpos, it works properly.

In the userform of my real project, I am resizing several frames. I'm wondering if that's somehow throwing it off. I'm going to go through this and strip out all the slop in my project first (just in case). I'm just learning VBA, so my organization here leaves a lot to be desired.

Then I'm going to do this without resizing frames and see if that's what is causing the problem.

Through the process of elimination, I will narrow this down :).
 
Upvote 0
Unfortunately, there's nothing to learn here. I copied my userform and module to a new project file. They work fine there. Something about this project file has been corrupted. I don't think I'll ever figure this out.
 
Upvote 0

Forum statistics

Threads
1,215,453
Messages
6,124,918
Members
449,195
Latest member
Stevenciu

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top