# OS-dependent flags in 'onMouseMove' callback

**URL:** <https://forums.sketchup.com/t/os-dependent-flags-in-onmousemove-callback/230386>\
**Category:** Ruby API\
**Created:** [May 17, 2023, 6:07pm UTC](https://forums.sketchup.com/t/os-dependent-flags-in-onmousemove-callback/230386 "2023-05-17T18:07:56Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![costica1234](https://avatars.discourse-cdn.com/v4/letter/c/839c29/32.png) [@costica1234](https://forums.sketchup.com/u/costica1234)\
**Post date:** [May 17, 2023, 6:07pm UTC](https://forums.sketchup.com/t/os-dependent-flags-in-onmousemove-callback/230386/1 "2023-05-17T18:07:56Z")

</div>

I’ve just encountered yet another inconsistency between macOS and Windows. This time around it happened while implementing the `onMouseMove(flags, x, y, view)` callback for a custom drawing tool that is supposed to update the geometry when the user selects an item (via left-click) and then drags the mouse cursor to a certain location.

Since I couldn’t find the possible values of `flags` in the documentation, I went ahead and printed the parameter to the console while developing my extension on macOS. Having found that `flags = 2` when dragging the mouse **and** holding down the left-button (or, in my case, pressing with one finger on the trackpad), I happily hard-coded that value without realizing that it might be different on my least-favorite OS, Windows.

Of course, the little extension I wrote didn’t work at all when switching to Windows. It didn’t take too long to narrow down why my code wasn’t working there, but the process of investigating and having to find the correct value (which is `1` instead of `2`) irked me a bit.

I find it baffling that the docs don’t say anything about the `flags` parameter and only provide the following “example” for all `Tool` callbacks:

```auto
def onMouseMove(flags, x, y, view)
  puts "onMouseMove: flags = #{flags}"
  puts " x = #{x}"
  puts " y = #{y}"
  puts " view = #{view}"
end

```

I really love the SketchUp Ruby API for everything it can do, but the documentation could at least be revamped to include more details about the differences between macOS and Windows. That would certainly improve the developer experience and make coding extensions a more enjoyable activity.

---

<div class="post-metadata">

**Author:** ![DanRathbun](https://sea2.discourse-cdn.com/sketchup/user_avatar/forums.sketchup.com/danrathbun/32/500_2.png) [@DanRathbun](https://forums.sketchup.com/u/DanRathbun)\
**Post date:** [May 17, 2023, 6:50pm UTC](https://forums.sketchup.com/t/os-dependent-flags-in-onmousemove-callback/230386/2 "2023-05-17T18:50:26Z")

</div>

> [@costica1234](#):
>
> I find it baffling that the docs don’t say anything about the `flags` parameter and only provide the following “example” for all `Tool` callbacks:

I think that the constants are listed in the [`Tool`](https://ruby.sketchup.com/Sketchup/Tool.html) class **Overview** section.

Also be aware that the API adds many cross-platform constants to the top level [`ObjectSpace`](https://ruby-doc.org/core-2.7.2/ObjectSpace.html).

- [Top Level Namespace — SketchUp Ruby API Documentation](https://ruby.sketchup.com/top-level-namespace.html)

These constants should always be used rather than hard-coded integers.

In addition, some API classes define cross-platform constants within the class context.

**Back to the mouse dragging.** The flags I think are for key modifiers, for like CTRL+mouse-click, etc.  
(I think,) to trap a drag, your tool will need to set a state variable `true` in the [`onLButtonDown`](https://ruby.sketchup.com/Sketchup/Tool.html#onLButtonDown-instance_method) callback. Then on the `onMouseMove` callback your conditional code would test that state variable to know if the mouse button was down. Eventually the user will release the mouse button which should be trapped in the [`onLButtonUp`](https://ruby.sketchup.com/Sketchup/Tool.html#onRButtonUp-instance_method) callback, which would unset your state variable.

> [@costica1234](#):
>
> I really love the SketchUp Ruby API for everything it can do, but the documentation could at least be revamped to include more details about the differences between macOS and Windows.

SketchUp’s API documentation has always been “behind”. Embarrassing considering that the customers are engineers using the product to **create documentation**.

At present there are 152 open documentation issues in the official API Issue tracker …

- [Open Ruby API Documentation Issues · SketchUp/api-issue-tracker (github.com)](https://github.com/SketchUp/api-issue-tracker/issues?q=is%3Aopen+is%3Aissue+label%3A%22Ruby+API%22+label%3Adocumentation)

If you find issues that do not have an open tracker issue, feel free to open a new issue. (Please avoid duplicates.)

---

<div class="post-metadata">

**Author:** ![costica1234](https://avatars.discourse-cdn.com/v4/letter/c/839c29/32.png) [@costica1234](https://forums.sketchup.com/u/costica1234)\
**Post date:** [May 17, 2023, 7:24pm UTC](https://forums.sketchup.com/t/os-dependent-flags-in-onmousemove-callback/230386/3 "2023-05-17T19:24:04Z")

</div>

> [@DanRathbun](#):
>
> The flags I think are for key modifiers, for like CTRL+mouse-click, etc.  
> (I think,) to trap a drag, your tool will need to set a state variable `true` in the [`onLButtonDown`](https://ruby.sketchup.com/Sketchup/Tool.html#onLButtonDown-instance_method) callback. Then on the `onMouseMove` callback your conditional code would test that state variable to know if the mouse button was down. Eventually the user will release the mouse button which should be trapped in the [`onLButtonUp`](https://ruby.sketchup.com/Sketchup/Tool.html#onRButtonUp-instance_method) callback, which would unset your state variable.

Oh, so the flags are for even more complex situations… And yes, I have actually implemented the exact same logic you described by setting and unsetting a state variable in those 2 callbacks. But I started off with the `flags` parameter and then added that state variable, so I didn’t realize that the very first condition was actually redundant.

Thanks again, Dan!

---

<div class="post-metadata">

**Author:** ![DanRathbun](https://sea2.discourse-cdn.com/sketchup/user_avatar/forums.sketchup.com/danrathbun/32/500_2.png) [@DanRathbun](https://forums.sketchup.com/u/DanRathbun)\
**Post date:** [May 17, 2023, 8:08pm UTC](https://forums.sketchup.com/t/os-dependent-flags-in-onmousemove-callback/230386/4 "2023-05-17T20:08:56Z")

</div>

> [@costica1234](#):
>
> And yes, I have actually implemented the exact same logic you described by setting and unsetting a state variable in those 2 callbacks.

FYI, I posted a test tool that traps dragging some time ago, in this API tracker issue :

[Sketchup::PickHelper window and boundingbox picks not correct in nested contexts · Issue #459](https://github.com/SketchUp/api-issue-tracker/issues/459)

… readers might glean some ideas from this.
