Welcome Guest.   Make a donation to an author on the site October 24, 2014, 09:53:48 PM  *

Please login or register.
Or did you miss your validation email?


Login with username and password (forgot your password?)
Why not become a lifetime supporting member of the site with a one-time donation of any amount? Your donation entitles you to a ton of additional benefits, including access to exclusive discounts and downloads, the ability to enter monthly free software drawings, and a single non-expiring license key for all of our programs.


You must sign up here before you can post and access some areas of the site. Registration is totally free and confidential.
 
Read the Practical Guide to DonationCoder.com Forum Search Features
   
   Forum Home   Thread Marks Chat! Downloads Search Login Register  
Pages: [1]   Go Down
  Reply  |  New Topic  |  Print  
Author Topic: SOLVED: autohotkey makes cursor slide - i want mouse movement to halt the slide  (Read 8945 times)
nudone
Cody's Creator
Columnist
***
Posts: 4,116



see users location on a map View Profile WWW Read user's biography. Give some DonationCredits to this forum member
« on: May 05, 2010, 05:10:22 PM »

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.

Formatted for AutoIt with the GeSHI Syntax Highlighter [copy or print]
  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


* SlideCursor.ahk (1.56 KB - downloaded 147 times.)
Logged
cranioscopical
Friend of the Site
Supporting Member
**
Posts: 4,182



see users location on a map View Profile Read user's biography. Give some DonationCredits to this forum member
« Reply #1 on: May 05, 2010, 06:03:35 PM »

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.
Logged

Chris
Target
Honorary Member
**
Posts: 1,410



see users location on a map View Profile WWW Give some DonationCredits to this forum member
« Reply #2 on: May 05, 2010, 06:24:22 PM »

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
[copy or print]
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)
Logged

"Look wise, say nothing, and grunt. Speech was given to conceal thought" - Sir William Osler
AndyM
Charter Member
***
Posts: 616


see users location on a map View Profile Give some DonationCredits to this forum member
« Reply #3 on: May 05, 2010, 09:24:21 PM »

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.
Grin
Logged
nudone
Cody's Creator
Columnist
***
Posts: 4,116



see users location on a map View Profile WWW Read user's biography. Give some DonationCredits to this forum member
« Reply #4 on: May 06, 2010, 02:38:23 AM »

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 » Logged
nudone
Cody's Creator
Columnist
***
Posts: 4,116



see users location on a map View Profile WWW Read user's biography. Give some DonationCredits to this forum member
« Reply #5 on: May 06, 2010, 05:13:56 AM »

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?

Formatted for AutoIt with the GeSHI Syntax Highlighter [copy or print]
  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. ypos -= speedmultiplier
  22. MouseMove, xpos, ypos, verticalspeed
  23.    if ypos = 0
  24. }
  25.  
  26. MoveDown:
  27. MouseGetPos, xpos, ypos
  28. loop
  29. {
  30.    MouseGetPos, xpos_,
  31.    if xpos_ <> %xpos%
  32. ypos += speedmultiplier
  33. MouseMove, xpos, ypos, verticalspeed
  34.    if ypos = %screenheight%
  35. }
  36.  
  37. MoveLeft:
  38. MouseGetPos, xpos, ypos
  39. loop
  40. {
  41.    MouseGetPos, , ypos_
  42.    if ypos_ <> %ypos%
  43. xpos -= speedmultiplier
  44. MouseMove, xpos, ypos, horizontalspeed
  45.    if xpos = 0
  46. }
  47.  
  48. MoveRight:
  49. MouseGetPos, xpos, ypos
  50. loop
  51. {
  52.    MouseGetPos, , ypos_
  53.    if ypos_ <> %ypos%
  54. xpos += speedmultiplier
  55. MouseMove, xpos, ypos, horizontalspeed
  56.    if xpos = %rightscreenwidth%
  57. }
Logged
skwire
Global Moderator
*****
Posts: 4,116



Another Coding Snack request? Om nom nom...

see users location on a map View Profile WWW Give some DonationCredits to this forum member
« Reply #6 on: May 06, 2010, 05:54:29 AM »

Adjust the FudgeFactor variable to your liking:

Formatted for AutoIt with the GeSHI Syntax Highlighter [copy or print]
  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. ypos -= speedmultiplier
  23. MouseMove, xpos, ypos, verticalspeed
  24.    if ypos = 0
  25. }
  26.  
  27. MoveDown:
  28. MouseGetPos, xpos, ypos
  29. loop
  30. {
  31.    MouseGetPos, xpos_,
  32.    If ( xpos_ < ( xpos - FudgeFactor ) OR ( xpos_ > ( xpos + FudgeFactor ) ) )
  33. ypos += speedmultiplier
  34. MouseMove, xpos, ypos, verticalspeed
  35.    if ypos = %screenheight%
  36. }
  37.  
  38. MoveLeft:
  39. MouseGetPos, xpos, ypos
  40. loop
  41. {
  42.    MouseGetPos, , ypos_
  43.    If ( ypos_ < ( ypos - FudgeFactor ) OR ( ypos_ > ( ypos + FudgeFactor ) ) )
  44. xpos -= speedmultiplier
  45. MouseMove, xpos, ypos, horizontalspeed
  46.    if xpos = 0
  47. }
  48.  
  49. MoveRight:
  50. MouseGetPos, xpos, ypos
  51. loop
  52. {
  53.    MouseGetPos, , ypos_
  54.    If ( ypos_ < ( ypos - FudgeFactor ) OR ( ypos_ > ( ypos + FudgeFactor ) ) )
  55. xpos += speedmultiplier
  56. MouseMove, xpos, ypos, horizontalspeed
  57.    if xpos = %rightscreenwidth%
  58. }
« Last Edit: May 06, 2010, 05:57:01 AM by skwire » Logged

nudone
Cody's Creator
Columnist
***
Posts: 4,116



see users location on a map View Profile WWW Read user's biography. Give some DonationCredits to this forum member
« Reply #7 on: May 06, 2010, 06:10:57 AM »

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 » Logged
Perry Mowbray
N.A.N.Y. Organizer
Charter Member
***
Posts: 1,807



Thoughtful Scribbles

see users location on a map View Profile WWW Read user's biography. Give some DonationCredits to this forum member
« Reply #8 on: May 06, 2010, 07:34:29 AM »

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).
Logged

nudone
Cody's Creator
Columnist
***
Posts: 4,116



see users location on a map View Profile WWW Read user's biography. Give some DonationCredits to this forum member
« Reply #9 on: May 06, 2010, 07:59:31 AM »

I think you'd need to be careful that you don't end up chasing your cursor all around your monitors?
good point.
Logged
nudone
Cody's Creator
Columnist
***
Posts: 4,116



see users location on a map View Profile WWW Read user's biography. Give some DonationCredits to this forum member
« Reply #10 on: May 06, 2010, 11:04:23 AM »

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.
Formatted for AutoIt with the GeSHI Syntax Highlighter [copy or print]
  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. ypos -= verticalspeedmultiplier
  35. MouseMove, xpos, ypos, verticalspeed
  36.    ;if ypos = 0
  37. if ypos < %TopEdge%
  38. }
  39.  
  40. MoveDown:
  41. ;CoordMode, Mouse, Screen
  42. MouseGetPos, xpos, ypos
  43. loop
  44. {
  45.    MouseGetPos, xpos_,
  46.    If ( xpos_ < ( xpos - FudgeFactor ) OR ( xpos_ > ( xpos + FudgeFactor ) ) )
  47. ypos += verticalspeedmultiplier
  48. MouseMove, xpos, ypos, verticalspeed
  49.    ;if ypos = %screenheight%
  50. if ypos > %BottomEdge%
  51. }
  52.  
  53. MoveLeft:
  54. MouseGetPos, xpos, ypos
  55. loop
  56. {
  57.    MouseGetPos, , ypos_
  58.    If ( ypos_ < ( ypos - FudgeFactorHorizontal ) OR ( ypos_ > ( ypos + FudgeFactorHorizontal ) ) )
  59. xpos -= horizontalspeedmultiplier
  60. MouseMove, xpos, ypos, horizontalspeed
  61.    ;if xpos = 0
  62. if xpos < %LeftEdge%
  63. }
  64.  
  65. MoveRight:
  66. MouseGetPos, xpos, ypos
  67. loop
  68. {
  69.    MouseGetPos, , ypos_
  70.    If ( ypos_ < ( ypos - FudgeFactorHorizontal ) OR ( ypos_ > ( ypos + FudgeFactorHorizontal ) ) )
  71. xpos += horizontalspeedmultiplier
  72. MouseMove, xpos, ypos, horizontalspeed
  73.    ;if xpos = %mainscreenwidth%
  74. if xpos > %RightEdge%
  75. }
« Last Edit: May 06, 2010, 11:06:02 AM by nudone » Logged
Perry Mowbray
N.A.N.Y. Organizer
Charter Member
***
Posts: 1,807



Thoughtful Scribbles

see users location on a map View Profile WWW Read user's biography. Give some DonationCredits to this forum member
« Reply #11 on: May 06, 2010, 05:39:23 PM »

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.autohotkey.com/forum/topic6107.html which actually leads to this one: http://www.autohotkey.com/forum/topic35600.html
« Last Edit: May 06, 2010, 05:43:02 PM by Perry Mowbray » Logged

Perry Mowbray
N.A.N.Y. Organizer
Charter Member
***
Posts: 1,807



Thoughtful Scribbles

see users location on a map View Profile WWW Read user's biography. Give some DonationCredits to this forum member
« Reply #12 on: May 06, 2010, 05:40:18 PM »

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?  cheesy Maybe you need a gameMode??
Logged

nudone
Cody's Creator
Columnist
***
Posts: 4,116



see users location on a map View Profile WWW Read user's biography. Give some DonationCredits to this forum member
« Reply #13 on: May 06, 2010, 07:35:11 PM »

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).
Logged
Target
Honorary Member
**
Posts: 1,410



see users location on a map View Profile WWW Give some DonationCredits to this forum member
« Reply #14 on: May 06, 2010, 08:02:34 PM »

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...)
Logged

"Look wise, say nothing, and grunt. Speech was given to conceal thought" - Sir William Osler
nudone
Cody's Creator
Columnist
***
Posts: 4,116



see users location on a map View Profile WWW Read user's biography. Give some DonationCredits to this forum member
« Reply #15 on: May 07, 2010, 04:23:44 AM »

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.
Logged
skwire
Global Moderator
*****
Posts: 4,116



Another Coding Snack request? Om nom nom...

see users location on a map View Profile WWW Give some DonationCredits to this forum member
« Reply #16 on: May 07, 2010, 05:09:13 AM »

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:

Formatted for AutoIt with the GeSHI Syntax Highlighter [copy or print]
  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. }

Then, to change the cursor, do the following:

Formatted for AutoIt with the GeSHI Syntax Highlighter [copy or print]
  1. Cursor := "C:\path\to\my\cursor.cur"
  2. SetSystemCursor( Cursor )

Or:

Formatted for AutoIt with the GeSHI Syntax Highlighter [copy or print]
  1. SetSystemCursor( "C:\path\to\my\cursor.cur" )

To restore the cursor, simply do:

Formatted for AutoIt with the GeSHI Syntax Highlighter [copy or print]
  1. RestoreCursors()
Logged

nudone
Cody's Creator
Columnist
***
Posts: 4,116



see users location on a map View Profile WWW Read user's biography. Give some DonationCredits to this forum member
« Reply #17 on: May 07, 2010, 05:30:23 AM »

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...
Logged
Pages: [1]   Go Up
  Reply  |  New Topic  |  Print  
 
Jump to:  
   Forum Home   Thread Marks Chat! Downloads Search Login Register  

DonationCoder.com | About Us
DonationCoder.com Forum | Powered by SMF
[ Page time: 0.686s | Server load: 0.17 ]