Page 1 of 1

custom cursor flickers

Posted: 06 Aug 2022, 13:23
by toralf
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

Re: custom cursor flickers  Topic is solved

Posted: 13 Aug 2022, 19:47
by thinkRand

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

Re: custom cursor flickers

Posted: 14 Aug 2022, 16:27
by toralf
Thanks a lot thinkRand

Re: custom cursor flickers

Posted: 15 Aug 2022, 20:08
by thinkRand
Alright, topic solved.