custom cursor flickers Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
toralf
Posts: 868
Joined: 27 Apr 2014, 21:08
Location: Germany

custom cursor flickers

Post by toralf » 06 Aug 2022, 13:23

Hi,

I have an AHK Gui on which i want to detect mouse drags.
The user is supposed to drag to move controls on the GUI.
Therefore I want to set a custom cursor to reflect that functionality.
But when I do it the custom curster flickers.
What could I do to have constant custom cursor while draging?

BTW: Using a the hotkey ~LButton:: didn't catch all the drags, so I switched to OnMessage().

Code: Select all

  CoordMode, Mouse, Screen
  Gui, Show, w300 h 300, Test MouseMoveDrag
  SIZEALL := DllCall("LoadCursor","UInt",NULL,"Int",32646,"UInt")
  OnMessage(0x200,"MouseMoveDrag") 
Return

; ~LButton:: MouseMoveDrag()

MouseMoveDrag(){
  global SIZEALL
  MouseGetPos, begin_x, begin_y
  ; ToolTip, % begin_x ", " begin_y
  If !GetKeyState("LButton")
    Return
  DllCall("SetCursor","UInt", SIZEALL)  
  while GetKeyState("LButton")
  {
    DllCall("SetCursor","UInt", SIZEALL)  
    MouseGetPos, x, y
    ToolTip, % begin_x ", " begin_y "`n" Abs(begin_x-x) " x " Abs(begin_y-y)
    Sleep, 10
  }
  ToolTip
}

Esc:: ExitApp
ciao
toralf

thinkRand
Posts: 44
Joined: 02 Mar 2022, 04:16
Location: Somewhere in Venezuela
Contact:

Re: custom cursor flickers  Topic is solved

Post by thinkRand » 13 Aug 2022, 19:47

Code: Select all

 CoordMode, Mouse, Screen

 
 Gui, Show, w300 h 300, Test MouseMoveDrag
 OnMessage(0x200,"MouseMoveDrag")
 OnMessage(0x20,"setCursor")
Return

; ~LButton:: MouseMoveDrag()


setCursor(wParam, lParam, msg, hwnd){
  return 0
}


MouseMoveDrag(){

  static SIZEALL := DllCall("LoadCursor", "UInt", 0, "Int", IDC_SIZEALL:=32646)

  MouseGetPos, begin_x, begin_y
  If !GetKeyState("LButton")
    Return
  prevCursor := DllCall("SetCursor","UInt", SIZEALL)
  
  while GetKeyState("LButton"){
    MouseGetPos, x, y
    ToolTip, % begin_x ", " begin_y "`n" Abs(begin_x-x) " x " Abs(begin_y-y)
    Sleep, 10
  }
  ToolTip
  DllCall("SetCursor","UInt", prevCursor)
}

Esc:: ExitApp
Discord: thinkRand#7433 (UID 681695022600814642)

toralf
Posts: 868
Joined: 27 Apr 2014, 21:08
Location: Germany

Re: custom cursor flickers

Post by toralf » 14 Aug 2022, 16:27

Thanks a lot thinkRand
ciao
toralf

thinkRand
Posts: 44
Joined: 02 Mar 2022, 04:16
Location: Somewhere in Venezuela
Contact:

Re: custom cursor flickers

Post by thinkRand » 15 Aug 2022, 20:08

Alright, topic solved.
Discord: thinkRand#7433 (UID 681695022600814642)

Post Reply

Return to “Ask for Help (v1)”