Skip to content

Instantly share code, notes, and snippets.

@ursi
Last active October 20, 2018 06:57
Show Gist options
  • Save ursi/133779423fb7f4445160703a2b031170 to your computer and use it in GitHub Desktop.
Save ursi/133779423fb7f4445160703a2b031170 to your computer and use it in GitHub Desktop.
setCursor(guiOrCont, cursor, options := 'n l r m'){
static cursors := {
appstarting: 32650,
arrow: 32512,
cross: 32515,
hand: 32649,
help: 32651,
ibeam: 32513,
no: 32648,
sizeall: 32646,
sizenesw: 32643,
sizens: 32645,
sizenwse: 32642,
sizewe: 32644,
uparrow: 32516,
wait: 32514,
hide: 0,
}
changeCurs(cursor2){
dllCall 'SetCursor', 'int', dllCall(
'LoadImageW',
'int', 0,
'int', cursors[cursor2],
'int', 2,
'int', 0,
'int', 0,
'int', 0x8000)
}
curCheckMove(wParam){
static guiObjs := {}
if not guiObjs[guiOrCont]
guiObjs[guiOrCont] := {}
downFlags := guiObjs[guiOrCont]
if gFlagL
downFlags.lDown := cursor
if gFlagR
downFlags.rDown := cursor
if gFlagM
downFlags.mDown := cursor
mouseGetPos ,, win, cont
if type(guiOrCont) != 'gui' and win = guiOrCont.gui.hwnd and cont = guiOrCont.classNN
or type(guiOrCont) = 'gui' and win = guiOrCont.hwnd and not cont{
if downFlags.lDown and wParam = 1
changeCurs(downFlags.lDown)
else if downFlags.rDown and wParam = 2
changeCurs(downFlags.rDown)
else if downFlags.mDown and wParam = 0x10
changeCurs(downFlags.mDown)
else if nFlag
changeCurs(cursor)
}
}
curCheckClick(){
mouseGetPos ,, win, cont
if type(guiOrCont) != 'gui' and win = guiOrCont.gui.hwnd and cont = guiOrCont.classNN
or type(guiOrCont) = 'gui' and win = guiOrCont.hwnd and not cont
changeCurs(cursor)
}
if options ~= 'i)n'
nFlag := 1
local gFlagL, gFlagR, gFlagM
flags := {l: 0, r: 3, m: 6}
for flag, offset in flags
if options ~= 'i)' flag{
regExMatch(options, flag '(\S+)', subOptions)
if not subOptions
loop 3
onMessage 0x200 + offset + a_index, 'curCheckClick'
else{
if subOptions.1 ~= 'i)d'
onMessage 0x201 + offset, 'curCheckClick'
if subOptions.1 ~= 'i)g'{
gFlag%flag% := 1
}
if subOptions.1 ~= 'i)u'
onMessage 0x202 + offset, 'curCheckClick'
if subOptions.1 ~= '2'
onMessage 0x203 + offset, 'curCheckClick'
}
}
onMessage 0x200, 'curCheckMove'
}
@ursi
Copy link
Author

ursi commented Oct 20, 2018

When the mouse is moved there can be a bit of flickering back to the default arrow. I have no idea how to fix this (please let me know if you do) but it's not too bad.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment