Website Home | Blog | Software | Reviews and Features | Forum | Help | Donate | About us
topbanner_forum
  *

avatar image

Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
  • August 30, 2015, 01:01:55 PM
  • Proudly celebrating 10 years online.
  • Donate now to become a lifetime supporting member of the site and get a non-expiring license key for all of our programs.
  • donate

Author Topic: SOLVED: autohotkey makes cursor slide - i want mouse movement to halt the slide  (Read 11030 times)

nudone

  • Cody's Creator
  • Columnist
  • Joined in 2005
  • ***
  • Posts: 4,117
    • View Profile
    • Read more about this member.
    • Donate to Member
i've been using this simple script to slide my cursor around my screen(s) by hitting buttons on my house (these buttons are just assigned to keyboard hotkeys that i'll never normally use).

i find the sliding method of moving the cursor very nice - it means i hardly have to move the mouse about on the mat and, i'm not sure why, but it just seems to feel nicer than using an accelerated cursor (i haven't got used to using skwire's MAT app).

REQUEST:
so, here's the request. although i like this sliding cursor motion - it has to carry out the full autohotkey "MouseMove" function before releasing the cursor - so i can't break the movement part way by moving the cursor with my mouse.

does that make sense? in other words: i'd like the buttons on my mouse to start the cursor sliding across the screen BUT as soon as i move the mouse myself - autohotkey releases the cursor and lets me take control.

i thought i'd be able to figure this out myself but i soon realised that the "MouseMove" function isn't something i can command to stop. well, not with my basic knowledge.

i've included my script if it helps - thanks.

Code: AutoIt
  1. ;SlideCursor
  2. ;By nudone
  3. ;date: 2010-04-26
  4. ScriptVersion=0.2
  5. ;function: Slides mouse cursor across whole screens. For multi-monitor systems.
  6.  
  7. ;CoordMode,Mouse,Screen ;this isn't used
  8. ;# = winkey, ! = alt, ^ = control, + = shift
  9.  
  10. Menu,Tray,Icon,%SystemRoot%\system32\SHELL32.dll,101
  11. Menu,Tray,Tip,SlideCursor %ScriptVersion%
  12.  
  13. Hotkey, #k,     MoveUp
  14. Hotkey, ^!+k,   MoveUp          ; * to work with programmable mouse buttons (if winkey not accepted)
  15. Hotkey, ^!+j,   MoveDown
  16. Hotkey, #j,     MoveDown        ; *
  17. Hotkey, #+j,    MoveLeft
  18. Hotkey, ^!+h,   MoveLeft        ; *
  19. Hotkey, #+k,    MoveRight
  20. Hotkey, ^!+l,   MoveRight       ; *
  21.  
  22. ;screen sizes
  23. TopScreenHeight=1080
  24. MiddleScreenWidth=1920
  25. LeftScreenWidth=1024
  26. RightScreenWidth=1024
  27.  
  28. ;mouse cursor movement speed
  29. VerticalSpeed=5 ; 0 = fastet, 100 = slowest
  30. HorizontalSpeed=10
  31.  
  32. ; Move the mouse upwards:
  33. MoveUp:
  34. MouseGetPos, xpos, ypos
  35. MouseMove, xpos, ypos - (TopScreenHeight*0.95), VerticalSpeed
  36.  
  37. ; Move the mouse downwards:
  38. MoveDown:
  39. MouseGetPos, xpos, ypos
  40. MouseMove, xpos, ypos + (TopScreenHeight*0.95), VerticalSpeed
  41.  
  42. ; Move the mouse to (far) left:
  43. MoveLeft:
  44. MouseGetPos, xpos, ypos
  45. ;MouseMove, xpos - MiddleScreenWidth - LeftScreenWidth , ypos, HorizontalSpeed ; use for 3 screens full travel
  46. MouseMove, xpos - LeftScreenWidth, ypos, HorizontalSpeed ;
  47.  
  48. ; Move the mouse to (far) right:
  49. MoveRight:
  50. MouseGetPos, xpos, ypos
  51. ;MouseMove, xpos + MiddleScreenWidth + LeftScreenWidth , ypos, HorizontalSpeed ;use for 3 screens full travel
  52. MouseMove, xpos + RightScreenWidth, ypos, HorizontalSpeed
  53.  


cranioscopical

  • Friend of the Site
  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 4,300
    • View Profile
    • Read more about this member.
    • Donate to Member
i've been using this simple script to slide my cursor around my screen(s) by hitting buttons on my house
Clearly you need to modify the home keys.

Target

  • Honorary Member
  • Joined in 2006
  • **
  • Posts: 1,500
    • View Profile
    • Donate to Member
Quote
i've been using this simple script to slide my cursor around my screen(s) by hitting buttons on my house...

for some reason this rang a bell with me too...

My initial thoughts on this would be to move the cursor incrementally within a loop (so there is something to break out of)

eg
Code: [Select]
mousegetpos, xpos, ypos

loop
{
    mousegetpos, , ypos_
    if ypos_ <> ypos
        break
    xpos++ 
    mousemove, xpos, ypos, horizontalspeed

    if xpos = %rightscreenwidth%
        Break
}
 

this is an example only - I haven't tested it, but it should break out of the loop when it reaches the screen width, or if the mouse position varies vertically (this being a horizontal movement)

AndyM

  • Charter Member
  • Joined in 2006
  • ***
  • Posts: 616
    • View Profile
    • Donate to Member
i've been using this simple script to slide my cursor around my screen(s) by hitting buttons on my house
Clearly you need to modify the home keys.
;D

nudone

  • Cody's Creator
  • Columnist
  • Joined in 2005
  • ***
  • Posts: 4,117
    • View Profile
    • Read more about this member.
    • Donate to Member
i've been using this simple script to slide my cursor around my screen(s) by hitting buttons on my house
Clearly you need to modify the home keys.
heheheh, oh dear. but very good cranioscopical.

thanks, Target, i will try your script out when i get chance later. it looks like it will work. i'll let you know. (nice bell pun by the way).
« Last Edit: May 06, 2010, 02:40:11 AM by nudone »

nudone

  • Cody's Creator
  • Columnist
  • Joined in 2005
  • ***
  • Posts: 4,117
    • View Profile
    • Read more about this member.
    • Donate to Member
okay, this is working fine (almost). i just had to change the if statement to use % % and it started working.

i've been trying to add a bit of a buffer, or error margin, so that the loop doesn't break instantly when it detects mouse movement - i'm sure it will feel better if the cursor is allowed to move slightly off course as it slides.

but, my logic and autohotkey knowledge aren't up to the task (i've not included my OR statements here as they are obviously just completely wrong).

could anyone (Target) see how to add a mouse movement buffer or margin to the script  below?

Code: AutoIt
  1. Hotkey, #k,     MoveUp
  2. Hotkey, ^!+k,   MoveUp          ; * to work with programmable mouse buttons (if winkey not accepted)
  3. Hotkey, ^!+j,   MoveDown
  4. Hotkey, #j,     MoveDown        ; *
  5. Hotkey, #+j,    MoveLeft
  6. Hotkey, ^!+h,   MoveLeft        ; *
  7. Hotkey, #+k,    MoveRight
  8. Hotkey, ^!+l,   MoveRight       ; *    
  9. horizontalspeed=0                       ; 0 = fastest, 100 = slowest
  10. verticalspeed=0
  11. speedmultiplier=30                      ; cursor movement needs speeding up a bit
  12. rightscreenwidth=1920           ; width of monitor
  13. screenheight=1200                       ; height of monitor
  14.  
  15. MoveUp:
  16. MouseGetPos, xpos, ypos
  17. loop
  18. {
  19.     MouseGetPos, xpos_,
  20.         if xpos_ <> %xpos%
  21.                 Break
  22.         ypos -= speedmultiplier
  23.         MouseMove, xpos, ypos, verticalspeed
  24.     if ypos = 0
  25.                 Break
  26. }
  27.  
  28. MoveDown:
  29. MouseGetPos, xpos, ypos
  30. loop
  31. {
  32.     MouseGetPos, xpos_,
  33.     if xpos_ <> %xpos%
  34.                 Break
  35.         ypos += speedmultiplier
  36.         MouseMove, xpos, ypos, verticalspeed
  37.     if ypos = %screenheight%
  38.                 Break
  39. }
  40.  
  41. MoveLeft:
  42. MouseGetPos, xpos, ypos
  43. loop
  44. {
  45.     MouseGetPos, , ypos_
  46.     if ypos_ <> %ypos%
  47.                 Break
  48.         xpos -= speedmultiplier
  49.         MouseMove, xpos, ypos, horizontalspeed
  50.     if xpos = 0
  51.                 Break
  52. }
  53.  
  54. MoveRight:
  55. MouseGetPos, xpos, ypos
  56. loop
  57. {
  58.     MouseGetPos, , ypos_
  59.     if ypos_ <> %ypos%
  60.                 Break
  61.         xpos += speedmultiplier
  62.         MouseMove, xpos, ypos, horizontalspeed
  63.     if xpos = %rightscreenwidth%
  64.                 Break
  65. }
  66.  

skwire

  • Global Moderator
  • Joined in 2005
  • *****
  • Posts: 4,390
    • View Profile
    • Donate to Member
Adjust the FudgeFactor variable to your liking:

Code: AutoIt
  1. Hotkey, #k,     MoveUp
  2. Hotkey, ^!+k,   MoveUp          ; * to work with programmable mouse buttons (if winkey not accepted)
  3. Hotkey, ^!+j,   MoveDown
  4. Hotkey, #j,     MoveDown        ; *
  5. Hotkey, #+j,    MoveLeft
  6. Hotkey, ^!+h,   MoveLeft        ; *
  7. Hotkey, #+k,    MoveRight
  8. Hotkey, ^!+l,   MoveRight       ; *    
  9. horizontalspeed=0                       ; 0 = fastest, 100 = slowest
  10. verticalspeed=0
  11. speedmultiplier=30                      ; cursor movement needs speeding up a bit
  12. rightscreenwidth=1920           ; width of monitor
  13. screenheight=1200                       ; height of monitor
  14. FudgeFactor=50
  15.  
  16. MoveUp:
  17. MouseGetPos, xpos, ypos
  18. loop
  19. {
  20.     MouseGetPos, xpos_,
  21.     If ( xpos_ < ( xpos - FudgeFactor ) OR ( xpos_ > ( xpos + FudgeFactor ) ) )
  22.                 Break
  23.         ypos -= speedmultiplier
  24.         MouseMove, xpos, ypos, verticalspeed
  25.     if ypos = 0
  26.                 Break
  27. }
  28.  
  29. MoveDown:
  30. MouseGetPos, xpos, ypos
  31. loop
  32. {
  33.     MouseGetPos, xpos_,
  34.     If ( xpos_ < ( xpos - FudgeFactor ) OR ( xpos_ > ( xpos + FudgeFactor ) ) )
  35.                 Break
  36.         ypos += speedmultiplier
  37.         MouseMove, xpos, ypos, verticalspeed
  38.     if ypos = %screenheight%
  39.                 Break
  40. }
  41.  
  42. MoveLeft:
  43. MouseGetPos, xpos, ypos
  44. loop
  45. {
  46.     MouseGetPos, , ypos_
  47.     If ( ypos_ < ( ypos - FudgeFactor ) OR ( ypos_ > ( ypos + FudgeFactor ) ) )
  48.                 Break
  49.         xpos -= speedmultiplier
  50.         MouseMove, xpos, ypos, horizontalspeed
  51.     if xpos = 0
  52.                 Break
  53. }
  54.  
  55. MoveRight:
  56. MouseGetPos, xpos, ypos
  57. loop
  58. {
  59.     MouseGetPos, , ypos_
  60.     If ( ypos_ < ( ypos - FudgeFactor ) OR ( ypos_ > ( ypos + FudgeFactor ) ) )
  61.                 Break
  62.         xpos += speedmultiplier
  63.         MouseMove, xpos, ypos, horizontalspeed
  64.     if xpos = %rightscreenwidth%
  65.                 Break
  66. }
  67.  
  68.  
« Last Edit: May 06, 2010, 05:57:01 AM by skwire »

nudone

  • Cody's Creator
  • Columnist
  • Joined in 2005
  • ***
  • Posts: 4,117
    • View Profile
    • Read more about this member.
    • Donate to Member
okay, that's great, skwire.

with FudgeFactor=10 and an added FudgeFactorHorizontal=2 (for horizontal cursor slides across the screen), it feels about right.

i'm happy with how things are now - but it would be a near perfect script if the cursor slide could "transition/merge" into the manual cursor movement when user moves the mouse. maybe that is expected way too much though as there could/would be times when the user wants to break the slide immediately - so a set transition would be annoying.

(p.s. i think my OR statement was missing a bracket as it looked about the same - that's reassuring that i wasn't totally out of my depth.)
« Last Edit: May 06, 2010, 06:13:18 AM by nudone »

Perry Mowbray

  • N.A.N.Y. Organizer
  • Charter Member
  • Joined in 2005
  • ***
  • Posts: 1,809
    • View Profile
    • Read more about this member.
    • Donate to Member
i'm happy with how things are now - but it would be a near perfect script if the cursor slide could "transition/merge" into the manual cursor movement when user moves the mouse. maybe that is expected way too much though as there could/would be times when the user wants to break the slide immediately - so a set transition would be annoying.

I think you'd need to be careful that you don't end up chasing your cursor all around your monitors?

This just reminded me of an Amiga mouse hack the kids loved... a rocket was launched when the programme ran and chased the cursor; the user moved the cursor away from the rocket which then changed course and kept chasing... until it caught up with the cursor and it exploded and the cursor disappeared: just long enough for you to wonder what you were going to do without a cursor (the first time anyway).

nudone

  • Cody's Creator
  • Columnist
  • Joined in 2005
  • ***
  • Posts: 4,117
    • View Profile
    • Read more about this member.
    • Donate to Member
I think you'd need to be careful that you don't end up chasing your cursor all around your monitors?
good point.

nudone

  • Cody's Creator
  • Columnist
  • Joined in 2005
  • ***
  • Posts: 4,117
    • View Profile
    • Read more about this member.
    • Donate to Member
i've updated the script slightly. it now calculates the "virtual" desktop covered by all of the monitors. it doesn't detect monitors being enabled/disabled so the script has to rerun if you are changing that kind of thing. it seems to work correctly, but then, i've based it on my inverted T screen layout (2 on top in the middle, 3 in a row along the bottom): 3 in a row works, 2 vertical works, all 4 works, and 1 main monitor works.

i have a request (that i know skwire knows the answer to), for switching the mouse cursor icon to another one - but only whilst the slide cursor function is in operation. i just think it would be nice if a giant cursor appeared whilst the sliding occured. i've had a look on the autohotkey forum but the dllcall function they are talking about for cursor swapping is beyond me.

i might try adding something to the script to detect which monitor the cursor is on. it might be handy for the cursor to travel automatically to the side and then up when trying to slide the cursor from the edge screen(s) to the top screen (and down and across when moving from the top screen to the side screens).

something like:
make cursor slide up
if cursor is on middle screen then slide up
else if cursor is on left screen then slide to right then up
else slide cursor to left and up

that sounds simple enough to my basic understanding of autohotkey.

i may also attempt to make the cursor slow down as it approaches the edges of the screen (as it did using the original MouseMove function).

here's the new script anyway.
Code: AutoIt
  1. SysGet, VirtualScreenLeft, 76   ; get the dimensions of the virtual desktop (all screens)
  2. SysGet, VirtualScreenWidth, 78
  3. SysGet, VirtualScreenTop, 77
  4. SysGet, VirtualScreenHeight, 79
  5. CoordMode, Mouse, Screen        ; make mouse coordinates relative to screen not active window
  6. Hotkey, #k,     MoveUp
  7. Hotkey, ^!+k,   MoveUp          ; * to work with programmable mouse buttons (if winkey not accepted)
  8. Hotkey, ^!+j,   MoveDown
  9. Hotkey, #j,     MoveDown        ; *
  10. Hotkey, #+j,    MoveLeft
  11. Hotkey, ^!+h,   MoveLeft        ; *
  12. Hotkey, #+k,    MoveRight
  13. Hotkey, ^!+l,   MoveRight       ; *    
  14. horizontalspeed = 0                     ; 0 = fastest, 100 = slowest
  15. verticalspeed =0
  16. verticalspeedmultiplier = 50                    ; cursor movement needs speeding up a bit
  17. horizontalspeedmultiplier = 70
  18. borderstop = 100                        ; border around screens to halt cursor slide
  19. mainscreenwidth = 1920          ; width of monitor
  20. TopEdge := VirtualScreenTop + borderstop                        ; topmost monitor edge
  21. BottomEdge := VirtualScreenHeight + VirtualScreenTop - borderstop ; bottommost monitor edge
  22. LeftEdge := VirtualScreenLeft + borderstop ; leftmost monitor
  23. RightEdge := VirtualScreenWidth + VirtualScreenLeft - borderstop ; rightmost monitor edge
  24. FudgeFactor=10                          ; margin of error for vertical slides
  25. FudgeFactorHorizontal=2         ; margin of error for horizontal slides
  26.  
  27. MoveUp:
  28. ;CoordMode, Mouse, Screen
  29. MouseGetPos, xpos, ypos
  30. loop
  31. {
  32.     MouseGetPos, xpos_,
  33.     If ( xpos_ < ( xpos - FudgeFactor ) OR ( xpos_ > ( xpos + FudgeFactor ) ) )
  34.                 Break
  35.         ypos -= verticalspeedmultiplier
  36.         MouseMove, xpos, ypos, verticalspeed
  37.     ;if ypos = 0
  38.         if ypos < %TopEdge%
  39.                 Break
  40. }
  41.  
  42. MoveDown:
  43. ;CoordMode, Mouse, Screen
  44. MouseGetPos, xpos, ypos
  45. loop
  46. {
  47.     MouseGetPos, xpos_,
  48.     If ( xpos_ < ( xpos - FudgeFactor ) OR ( xpos_ > ( xpos + FudgeFactor ) ) )
  49.                 Break
  50.         ypos += verticalspeedmultiplier
  51.         MouseMove, xpos, ypos, verticalspeed
  52.     ;if ypos = %screenheight%
  53.         if ypos > %BottomEdge%
  54.                 Break
  55. }
  56.  
  57. MoveLeft:
  58. MouseGetPos, xpos, ypos
  59. loop
  60. {
  61.     MouseGetPos, , ypos_
  62.     If ( ypos_ < ( ypos - FudgeFactorHorizontal ) OR ( ypos_ > ( ypos + FudgeFactorHorizontal ) ) )
  63.                 Break
  64.         xpos -= horizontalspeedmultiplier
  65.         MouseMove, xpos, ypos, horizontalspeed
  66.     ;if xpos = 0
  67.         if xpos < %LeftEdge%
  68.                 Break
  69. }
  70.  
  71. MoveRight:
  72. MouseGetPos, xpos, ypos
  73. loop
  74. {
  75.     MouseGetPos, , ypos_
  76.     If ( ypos_ < ( ypos - FudgeFactorHorizontal ) OR ( ypos_ > ( ypos + FudgeFactorHorizontal ) ) )
  77.                 Break
  78.         xpos += horizontalspeedmultiplier
  79.         MouseMove, xpos, ypos, horizontalspeed
  80.     ;if xpos = %mainscreenwidth%
  81.         if xpos > %RightEdge%
  82.                 Break
  83. }
  84.  
« Last Edit: May 06, 2010, 11:06:02 AM by nudone »

Perry Mowbray

  • N.A.N.Y. Organizer
  • Charter Member
  • Joined in 2005
  • ***
  • Posts: 1,809
    • View Profile
    • Read more about this member.
    • Donate to Member
i have a request (that i know skwire knows the answer to), for switching the mouse cursor icon to another one - but only whilst the slide cursor function is in operation. i just think it would be nice if a giant cursor appeared whilst the sliding occured. i've had a look on the autohotkey forum but the dllcall function they are talking about for cursor swapping is beyond me.

You mean this one: http://www.autohotke...forum/topic6107.html which actually leads to this one: http://www.autohotke...orum/topic35600.html
« Last Edit: May 06, 2010, 05:43:02 PM by Perry Mowbray »

Perry Mowbray

  • N.A.N.Y. Organizer
  • Charter Member
  • Joined in 2005
  • ***
  • Posts: 1,809
    • View Profile
    • Read more about this member.
    • Donate to Member
I think you'd need to be careful that you don't end up chasing your cursor all around your monitors?
good point.

In hindsight I think it may be a good idea for a game?  :D Maybe you need a gameMode??

nudone

  • Cody's Creator
  • Columnist
  • Joined in 2005
  • ***
  • Posts: 4,117
    • View Profile
    • Read more about this member.
    • Donate to Member
You mean this one: http://www.autohotke...forum/topic6107.html
yes, they are what i saw - and became no less confused after reading them. i will try to understand it, maybe it's very simple.

i have enough fun with this sliding cursor as it is - but you are welcome to modify it into a game, Perry (truth is, it takes me too long to accomplish anything with autohotkey to try "fun" stuff).

Target

  • Honorary Member
  • Joined in 2006
  • **
  • Posts: 1,500
    • View Profile
    • Donate to Member
i have enough fun with this sliding cursor as it is - but you are welcome to modify it into a game, Perry (truth is, it takes me too long to accomplish anything with autohotkey to try "fun" stuff).

it's all fun (in a hair tearing, teeth grinding kind of way...)

nudone

  • Cody's Creator
  • Columnist
  • Joined in 2005
  • ***
  • Posts: 4,117
    • View Profile
    • Read more about this member.
    • Donate to Member
i mentioned above that i might try and adapt the script so that it will make the cursor travel around corners - moving from a lower corner screen to the upper middle screen (and vice versa).

but it appears the the script allows for this already, in a buggy kind of way. so that is fortunate.

skwire

  • Global Moderator
  • Joined in 2005
  • *****
  • Posts: 4,390
    • View Profile
    • Donate to Member
yes, they are what i saw - and became no less confused after reading them. i will try to understand it, maybe it's very simple.

It is rather simple since Serenity wrapped the functions nicely.  Simply add the following function definitions to the BOTTOM of your script:

Code: AutoIt
  1. RestoreCursors()
  2. {
  3.    SPI_SETCURSORS := 0x57
  4.    DllCall( "SystemParametersInfo", UInt,SPI_SETCURSORS, UInt,0, UInt,0, UInt,0 )
  5. }
  6.  
  7. SetSystemCursor( Cursor = "", cx = 0, cy = 0 )
  8. {
  9.    BlankCursor := 0, SystemCursor := 0, FileCursor := 0 ; init
  10.    
  11.    SystemCursors = 32512IDC_ARROW,32513IDC_IBEAM,32514IDC_WAIT,32515IDC_CROSS
  12.    ,32516IDC_UPARROW,32640IDC_SIZE,32641IDC_ICON,32642IDC_SIZENWSE
  13.    ,32643IDC_SIZENESW,32644IDC_SIZEWE,32645IDC_SIZENS,32646IDC_SIZEALL
  14.    ,32648IDC_NO,32649IDC_HAND,32650IDC_APPSTARTING,32651IDC_HELP
  15.    
  16.    If Cursor = ; empty, so create blank cursor
  17.    {
  18.       VarSetCapacity( AndMask, 32*4, 0xFF ), VarSetCapacity( XorMask, 32*4, 0 )
  19.       BlankCursor = 1 ; flag for later
  20.    }
  21.    Else If SubStr( Cursor,1,4 ) = "IDC_" ; load system cursor
  22.    {
  23.       Loop, Parse, SystemCursors, `,
  24.       {
  25.          CursorName := SubStr( A_Loopfield, 6, 15 ) ; get the cursor name, no trailing space with substr
  26.          CursorID := SubStr( A_Loopfield, 1, 5 ) ; get the cursor id
  27.          SystemCursor = 1
  28.          If ( CursorName = Cursor )
  29.          {
  30.             CursorHandle := DllCall( "LoadCursor", Uint,0, Int,CursorID )  
  31.             Break              
  32.          }
  33.       }  
  34.       If CursorHandle = ; invalid cursor name given
  35.       {
  36.          Msgbox,, SetCursor, Error: Invalid cursor name
  37.          CursorHandle = Error
  38.       }
  39.    }  
  40.    Else If FileExist( Cursor )
  41.    {
  42.       SplitPath, Cursor,,, Ext ; auto-detect type
  43.       If Ext = ico
  44.          uType := 0x1  
  45.       Else If Ext in cur,ani
  46.          uType := 0x2      
  47.       Else ; invalid file ext
  48.       {
  49.          Msgbox,, SetCursor, Error: Invalid file type
  50.          CursorHandle = Error
  51.       }      
  52.       FileCursor = 1
  53.    }
  54.    Else
  55.    {  
  56.       Msgbox,, SetCursor, Error: Invalid file path or cursor name
  57.       CursorHandle = Error ; raise for later
  58.    }
  59.    If CursorHandle != Error
  60.    {
  61.       Loop, Parse, SystemCursors, `,
  62.       {
  63.          If BlankCursor = 1
  64.          {
  65.             Type = BlankCursor
  66.             %Type%%A_Index% := DllCall( "CreateCursor"
  67.             , Uint,0, Int,0, Int,0, Int,32, Int,32, Uint,&AndMask, Uint,&XorMask )
  68.             CursorHandle := DllCall( "CopyImage", Uint,%Type%%A_Index%, Uint,0x2, Int,0, Int,0, Int,0 )
  69.             DllCall( "SetSystemCursor", Uint,CursorHandle, Int,SubStr( A_Loopfield, 1, 5 ) )
  70.          }        
  71.          Else If SystemCursor = 1
  72.          {
  73.             Type = SystemCursor
  74.             CursorHandle := DllCall( "LoadCursor", Uint,0, Int,CursorID )  
  75.             %Type%%A_Index% := DllCall( "CopyImage"
  76.             , Uint,CursorHandle, Uint,0x2, Int,cx, Int,cy, Uint,0 )      
  77.             CursorHandle := DllCall( "CopyImage", Uint,%Type%%A_Index%, Uint,0x2, Int,0, Int,0, Int,0 )
  78.             DllCall( "SetSystemCursor", Uint,CursorHandle, Int,SubStr( A_Loopfield, 1, 5 ) )
  79.          }
  80.          Else If FileCursor = 1
  81.          {
  82.             Type = FileCursor
  83.             %Type%%A_Index% := DllCall( "LoadImageA"
  84.             , UInt,0, Str,Cursor, UInt,uType, Int,cx, Int,cy, UInt,0x10 )
  85.             DllCall( "SetSystemCursor", Uint,%Type%%A_Index%, Int,SubStr( A_Loopfield, 1, 5 ) )        
  86.          }        
  87.       }
  88.    }  
  89. }
  90.  

Then, to change the cursor, do the following:

Code: AutoIt
  1. Cursor := "C:\path\to\my\cursor.cur"
  2. SetSystemCursor( Cursor )
  3.  

Or:

Code: AutoIt
  1. SetSystemCursor( "C:\path\to\my\cursor.cur" )
  2.  

To restore the cursor, simply do:

Code: AutoIt
  1. RestoreCursors()
  2.  

nudone

  • Cody's Creator
  • Columnist
  • Joined in 2005
  • ***
  • Posts: 4,117
    • View Profile
    • Read more about this member.
    • Donate to Member
thank you very much for explaining that, skwire. i might have understood it after a (few) rereads, i just couldn't figure out what was important and what was noise in the thread.

i'll go and implement it now...