Jump to content

Recommended Posts

Posted

I'm trying remap dragging with right mouse button in OrcaSlicer so it would do the same as CTRL+ALT+LeftMouse. I was successful with using logitech software for my mouse, however it removed simple right click capabilities.

So autoit for the rescue, I hope.

So far, I come up with this code which uses MouseOnEvent UDF:
 

;~ #include <_debug.au3>
#include <Misc.au3>
#include <MouseOnEvent.au3>

Global $isRightMouse = false
Global $isRotateStarted = false

Func debug($text)
    ConsoleWrite($text & @CRLF)
EndFunc

Func _secondaryDown()
    $isRightMouse = true
EndFunc

Func _secondaryUp()
    $isRightMouse = false
    if $isRotateStarted Then
        debug("rotate stopped")
        send("{CTRLUP}{ALTUP}")
        MouseUp("left")
    EndIf
    $isRotateStarted = false
EndFunc

Func _mouseMove()
    If Not $isRotateStarted And $isRightMouse Then
        $isRotateStarted = true
        Send("{CTRLDOWN}{ALTDOWN}")
        MouseDown("left")
        debug("rotate started")
    EndIf
EndFunc

_MouseSetOnEvent($MOUSE_MOVE_EVENT, "_mouseMove")
_MouseSetOnEvent($MOUSE_SECONDARYDOWN_EVENT, "_secondaryDown")
_MouseSetOnEvent($MOUSE_SECONDARYUP_EVENT, "_secondaryUp")

; Idle
While 1
   if _IsPressed("1B") Then ExitLoop
   Sleep(10)
Wend

_MouseSetOnEvent($MOUSE_SECONDARYUP_EVENT)
_MouseSetOnEvent($MOUSE_SECONDARYDOWN_EVENT)

 

For the most part it works fine, except for one tiny issue: when I drag with right mouse button for the second time the cursor freezes and moves ones a second, I can't even kill the script via task manager (access denied WTF!) Requires reboot to revive the system.

Any ideas what could be wring with the code and any other suggestions how to achieve this?

Thank you!

P.S.

And to answer invadable questions "why do you need this?":

OrcaSlicer as well as BambuStudio have the most idiotic controls: dragging with left click will rotate the world unless(!!!) cursor is pointing at an object. than it moves the object instead. While dragging with right or middle mouse buttons does exactly same thing: panning.

Dragging with left mouse button while CTRL+ALT are held rotates the world regardless of what cursor is pointing at.

So, simulating CTRL+ALT+LeftMouse drag via single RightMouse drag would free up my other hand for more important tasks and mostly would leave my sanity alone.

Posted (edited)

It does not occur on my side when I run your code.  Of course I do not own your apps, so not a valid conclusion.  But I see one issue, it seems that the right clicks (up and down) are going through while they should be canceled.  I do not know this UDF, so you should investigate if it can stop the right clicks going to the application.  I know it is possible with the kind of hook this UDF uses...

ps.  if you call a reboot of the system a tiny issue, I wouldn't like to see one of your big issues. ;)

Edited by Nine
Posted (edited)

That’s a clever approach! Remapping the right mouse button for dragging while keeping its normal click function can be tricky. AutoIt should definitely help with that. Curious to see how your script handles both right-clicking and dragging—were you able to get it working smoothly? Also, don’t forget to Testez votre vitesse de clics and see how fast your mouse clicking speed really is

Edited by AntoinetteBArnold
Posted (edited)
5 hours ago, AntoinetteBArnold said:

right mouse button for dragging while still keeping its normal click function can be tricky

Not that complicated.  You just need to check if the mouse down and mouse up are at the same position.  If it is, then it's a mouse click, if not then it is a drag.  The tricky part comes from not allowing the right click to go thru the application when it is a drag, and let it go thru if it is a simple click.  But it is quite doable with a bit of logic...

Edited by Nine
Posted (edited)

It seems at least on my system, when I execute MouseDown() or MouseUp() functions from within mouse event handler function, it makes my system unusable.

So, as a work around, I tried move everything into main loop, which seems to "work", however OrcaSlicer ignores CTRL+ALT combinations for some reason, but right click now rotates the world even though there is 10ms delay and it still pans the world for a few pixels too:

;~ #include <_debug.au3>
#include <Misc.au3>
#include <MouseOnEvent.au3>

Global $isSecondary = false
Global $isDragging = false
Global $dragging = false
;make sure we only execute functions once
Global $doDown = false
Global $doUp = false

Func debug($text)
    ConsoleWrite($text & @CRLF)
EndFunc

Func _secondaryDown()
    $isSecondary = true
    debug("_ mouse down")
EndFunc

Func _secondaryUp()
    debug("_ mouse up")
    $isSecondary = false
    $return = 0
    if $isDragging Then
        debug("dragging is stopping")
        $doUp = true
    elseif $dragging Then
        debug("dragging stopped" & @CRLF)
        $doUp = false
        $dragging = false
        $return = $MOE_BLOCKDEFPROC ;Block
    EndIf
    $isDragging = false
    return $return
EndFunc

Func _mouseMove()
    If $isDragging Or Not $isSecondary Then Return

    debug("_ mouse move")
    ;~ Send("{CTRLDOWN}{ALTDOWN}")
    $isDragging = true
    $dragging = true
    $doDown = true
    debug("dragging started")
EndFunc

Func doUp()
    debug("do up")
    $doUp = false
    MouseUp($MOUSE_CLICK_PRIMARY)
    Send("{CTRLUP}{ALTUP}")
    MouseUp($MOUSE_CLICK_SECONDARY)
EndFunc

Func doDown()
    debug("do down")
    $doDown = false
    Send("{CTRLDOWN}{ALTDOWN}")
    MouseDown($MOUSE_CLICK_PRIMARY)
EndFunc

; Set events
_MouseSetOnEvent($MOUSE_MOVE_EVENT, "_mouseMove")
_MouseSetOnEvent($MOUSE_SECONDARYDOWN_EVENT, "_secondaryDown")
_MouseSetOnEvent($MOUSE_SECONDARYUP_EVENT, "_secondaryUp")

; Idle
While 1
    if _IsPressed("1B") Then ExitLoop ; ESC
    if $doDown Then doDown()
    if $doUp Then doUp()
    Sleep(10)
Wend

; Reset events when done
_MouseSetOnEvent($MOUSE_SECONDARYUP_EVENT)
_MouseSetOnEvent($MOUSE_SECONDARYDOWN_EVENT)
_MouseSetOnEvent($MOUSE_MOVE_EVENT)

P.S.

Any help is highly appreciated, the OrcsSlicer has portable version without installation in case someone is willing to try.

Edited by VAN0

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...