x cursor position does not work Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Guest

x cursor position does not work  Topic is solved

18 Jan 2018, 08:09

Hello! I'm a beginner and need some helps.

This code works (apparently?) very well and prints the x cursor position .

Code: Select all

CursorPositionX() 
{
  clipboard = 
  Sendinput +{Home}^c^v
  return StrLen(clipboard)
}
^w::
tmp := clipboard
msgbox % CursorPositionX()
clipboard := tmp
The following should be even more "sure" (to me) but it works only sometimes. Why??????

Code: Select all

CursorPositionX() 
{
  clipboard = 
  Sendinput +{Home}^c ; differences are here
  ClipWait 0.1 ;  here 
  Sendinput ^v ; and here
  return StrLen(clipboard)
}

^w::
tmp := clipboard
msgbox % CursorPositionX()
clipboard := tmp

Guest2018

Re: x cursor position does not work

18 Jan 2018, 10:01

Hi,

To be honest I can't say anything about your codes, but I make the same thing in a different way.

Code: Select all

^+!F4::
CoordMode, Mouse, Screen
MouseGetPos, xx, yy
Clipboard = Cursor is at: %xx%, %yy%
return
CoordMode, Mouse, Screen means the cursor position is always taken from the whole screen.
If you want the cursor position to be relative to your active window, remove everything, so only:

Code: Select all

^+!F4::
MouseGetPos, xx, yy
Clipboard = Cursor is at: %xx%, %yy%
return
Of course you can change the hotkey (In this case it's Ctrl+Shift+Alt+F4) and the variables.
Rohwedder
Posts: 7644
Joined: 04 Jun 2014, 08:33
Location: Germany

Re: x cursor position does not work

18 Jan 2018, 10:34

Hallo,
maybe with slower sends?

Code: Select all

CursorPositionX() 
{
  clipboard = 
  SetKeyDelay, 30,20
  Send +{Home}^c
  ClipWait .1
  Send ^v 
  return StrLen(clipboard)
}

^w::
tmp := clipboardall
msgbox % CursorPositionX()
clipboard := tmp
Return

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Chunjee, inseption86, jaka1, LuckyJoe, Rohwedder and 333 guests