# Detecting mouse hover?

**URL:** <https://forum.cabbageaudio.com/t/detecting-mouse-hover/2446>\
**Category:** Cabbage Stew\
**Created:** [12 April 2021 19:44 UTC](https://forum.cabbageaudio.com/t/detecting-mouse-hover/2446 "2021-04-12T19:44:36Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![fellusive](https://forum.cabbageaudio.com/user_avatar/forum.cabbageaudio.com/fellusive/32/4515_2.png) [@fellusive](https://forum.cabbageaudio.com/u/fellusive)\
**Post date:** [12 April 2021 19:44 UTC](https://forum.cabbageaudio.com/t/detecting-mouse-hover/2446/1 "2021-04-12T19:44:36Z")

</div>

Would it be possible for some kinda opcode or something to send a message if the mouse is hovering over a widget? Or would this be too complicated/risky to implement?

For context, I was just thinking of the possibility for a user to toggle descriptions or other widgets’ visibility by simply hovering over a widget, since that behavior can be found in some plugins out there (Valhalla, for example).

---

<div class="post-metadata">

**Author:** ![hdale94](https://forum.cabbageaudio.com/user_avatar/forum.cabbageaudio.com/hdale94/32/6371_2.png) [@hdale94](https://forum.cabbageaudio.com/u/hdale94)\
**Post date:** [12 April 2021 19:57 UTC](https://forum.cabbageaudio.com/t/detecting-mouse-hover/2446/2 "2021-04-12T19:57:02Z")

</div>

[https://cabbageaudio.com/docs/macros\_and\_reserved\_channels/](https://cabbageaudio.com/docs/macros_and_reserved_channels/)

Might find something useful here.

---

<div class="post-metadata">

**Author:** ![fellusive](https://forum.cabbageaudio.com/user_avatar/forum.cabbageaudio.com/fellusive/32/4515_2.png) [@fellusive](https://forum.cabbageaudio.com/u/fellusive)\
**Post date:** [12 April 2021 20:38 UTC](https://forum.cabbageaudio.com/t/detecting-mouse-hover/2446/3 "2021-04-12T20:38:47Z")

</div>

Oh yeah, this is very useful. Really cool features here! Thanks for pointing this page out to me, I totally overlooked it.

---

<div class="post-metadata">

**Author:** ![rorywalsh](https://forum.cabbageaudio.com/user_avatar/forum.cabbageaudio.com/rorywalsh/32/165_2.png) [@rorywalsh](https://forum.cabbageaudio.com/u/rorywalsh)\
**Post date:** [12 April 2021 21:35 UTC](https://forum.cabbageaudio.com/t/detecting-mouse-hover/2446/4 "2021-04-12T21:35:51Z")

</div>

A new addition to that list is `CURRENT_WIDGET`, that will return the channel of the widget the mouse is currently hovering over. 👍

[edit] btw, the docs need updating. The latest version of that list can be read [here](https://github.com/rorywalsh/cabbage/blob/develop/Docs/markdown/macros_and_reserved_channels.md)

---

<div class="post-metadata">

**Author:** ![rorywalsh](https://forum.cabbageaudio.com/user_avatar/forum.cabbageaudio.com/rorywalsh/32/165_2.png) [@rorywalsh](https://forum.cabbageaudio.com/u/rorywalsh)\
**Post date:** [14 April 2021 11:25 UTC](https://forum.cabbageaudio.com/t/detecting-mouse-hover/2446/5 "2021-04-14T11:25:46Z")

</div>

@fellusive, you can also use a custom identifiers for this. I’ve prepared a simple example.  
[CustomInfo.csd](https://forum.cabbageaudio.com/uploads/short-url/mZrzrI3GNQb6uySkWwOPfcF5zoq.csd) (798 Bytes)

![2021-04-14 12.24.24](https://forum.cabbageaudio.com/uploads/default/original/2X/6/6c488b1fe1067d3b979934e9edcff2559809f660.gif)

[edit] you will need to use the latest version of Cabbage for this. There was a bug in the `cabbageGet` opcode when an empty string was passed as a channel. Fixed now.

---

<div class="post-metadata">

**Author:** ![fellusive](https://forum.cabbageaudio.com/user_avatar/forum.cabbageaudio.com/fellusive/32/4515_2.png) [@fellusive](https://forum.cabbageaudio.com/u/fellusive)\
**Post date:** [14 April 2021 14:31 UTC](https://forum.cabbageaudio.com/t/detecting-mouse-hover/2446/6 "2021-04-14T14:31:50Z")

</div>

Whoa, this is really cool. I understand what’s going on in the instrument by watching the .gif you attached, but for some reason Cabbage crashes if I try to run the instrument on my own computer (macOS, 10.14.6). I’m using the most recent version of Cabbage and Csound.

I’ll try to mess around with the ideas you’ve shown here - thanks for sharing this 🙂

---

<div class="post-metadata">

**Author:** ![rorywalsh](https://forum.cabbageaudio.com/user_avatar/forum.cabbageaudio.com/rorywalsh/32/165_2.png) [@rorywalsh](https://forum.cabbageaudio.com/u/rorywalsh)\
**Post date:** [14 April 2021 15:52 UTC](https://forum.cabbageaudio.com/t/detecting-mouse-hover/2446/7 "2021-04-14T15:52:19Z")

</div>

When you say recent, fo you mean [this](https://dev.azure.com/rorywalsh/cabbage/_build/results?buildId=1254&view=artifacts&pathAsName=false&type=publishedArtifacts) version, it only finished building a few hours ago.

---

<div class="post-metadata">

**Author:** ![fellusive](https://forum.cabbageaudio.com/user_avatar/forum.cabbageaudio.com/fellusive/32/4515_2.png) [@fellusive](https://forum.cabbageaudio.com/u/fellusive)\
**Post date:** [14 April 2021 15:57 UTC](https://forum.cabbageaudio.com/t/detecting-mouse-hover/2446/8 "2021-04-14T15:57:37Z")

</div>

Yep - I’m testing stuff out right now, and so far the culprit seems to be having multiple arguments in cabbageGet’s input.

---

<div class="post-metadata">

**Author:** ![rorywalsh](https://forum.cabbageaudio.com/user_avatar/forum.cabbageaudio.com/rorywalsh/32/165_2.png) [@rorywalsh](https://forum.cabbageaudio.com/u/rorywalsh)\
**Post date:** [14 April 2021 16:03 UTC](https://forum.cabbageaudio.com/t/detecting-mouse-hover/2446/9 "2021-04-14T16:03:42Z")

</div>

So it’s not working for you with the cod I posted? let me check that version myself, maybe I forgot to push through some changes…

---

<div class="post-metadata">

**Author:** ![rorywalsh](https://forum.cabbageaudio.com/user_avatar/forum.cabbageaudio.com/rorywalsh/32/165_2.png) [@rorywalsh](https://forum.cabbageaudio.com/u/rorywalsh)\
**Post date:** [14 April 2021 16:06 UTC](https://forum.cabbageaudio.com/t/detecting-mouse-hover/2446/10 "2021-04-14T16:06:21Z")

</div>

eh, sorry 🤣 I never pushed the bug fix I mentioned through to git! I just pushed it now. Should be ready in short while. Let me know if it works Ok!

---

<div class="post-metadata">

**Author:** ![fellusive](https://forum.cabbageaudio.com/user_avatar/forum.cabbageaudio.com/fellusive/32/4515_2.png) [@fellusive](https://forum.cabbageaudio.com/u/fellusive)\
**Post date:** [14 April 2021 17:45 UTC](https://forum.cabbageaudio.com/t/detecting-mouse-hover/2446/11 "2021-04-14T17:45:52Z")

</div>

Works ok now! Thanks for the fix

---

<div class="post-metadata">

**Author:** ![fellusive](https://forum.cabbageaudio.com/user_avatar/forum.cabbageaudio.com/fellusive/32/4515_2.png) [@fellusive](https://forum.cabbageaudio.com/u/fellusive)\
**Post date:** [14 April 2021 18:29 UTC](https://forum.cabbageaudio.com/t/detecting-mouse-hover/2446/12 "2021-04-14T18:29:00Z")

</div>

Hmm I apologize for the potentially noob question. Since `cabbageGet "CURRENT_WIDGET"` doesn’t seem to return anything if the mouse is hovering over something like an image/label, how would one describe this “null” value in Csound?

Basically what I’m trying to do in my instrument is send a `visible(0)` message to something if the mouse isn’t hovering over an interactive widget, and it’d be much more concise if I knew what to compare the output of `cabbageGet "CURRENT_WIDGET"` to in order to execute this. For reference…

```
SWidgetName cabbageGet "CURRENT_WIDGET"   

     if (SWidgetName==NULL) then 

        SIdent sprintfk "visible(0)", gkGain
        chnset SIdent, "label" 

     endif

```

…where “NULL” is the thing I’m trying to figure out the replacement for.

---

<div class="post-metadata">

**Author:** ![rorywalsh](https://forum.cabbageaudio.com/user_avatar/forum.cabbageaudio.com/rorywalsh/32/165_2.png) [@rorywalsh](https://forum.cabbageaudio.com/u/rorywalsh)\
**Post date:** [14 April 2021 19:16 UTC](https://forum.cabbageaudio.com/t/detecting-mouse-hover/2446/13 "2021-04-14T19:16:32Z")

</div>

SWidgetName will always be the last widget that had a channel name. If you want to do this with the new widgets just set a custom identifier that you can query to let you know if you want to make something invisible, for example:

`label bounds(34, 158, 168, 22), channel("Label1"), text("I'm a label"), _shouldHide(1)`

Then:

```
instr 1
    SWidgetName, kTrigger cabbageGet "CURRENT_WIDGET"
    kShouldHide cabbageGet SWidgetName, "_shouldHide"
    
    if kTrigger == 1 && kShouldHide == 1 then
        cabbageSet kTrigger, SWidgetName, "visible(0)" 
    endif 
endin

```

[CustomInfo.csd](https://forum.cabbageaudio.com/uploads/short-url/mvR1gtIn7zNw7IEWBOLWtjhYY6x.csd) (1.1 KB)

![2021-04-14 20.12.37](https://forum.cabbageaudio.com/uploads/default/original/2X/a/acf02a5ab9848b79e56dbf90cd3dac898fcbc936.gif)

Note this one also needs an update! But lucky for you it’s already [built](https://dev.azure.com/rorywalsh/cabbage/_build/results?buildId=1255&view=artifacts&pathAsName=false&type=publishedArtifacts)

---

<div class="post-metadata">

**Author:** ![fellusive](https://forum.cabbageaudio.com/user_avatar/forum.cabbageaudio.com/fellusive/32/4515_2.png) [@fellusive](https://forum.cabbageaudio.com/u/fellusive)\
**Post date:** [14 April 2021 21:39 UTC](https://forum.cabbageaudio.com/t/detecting-mouse-hover/2446/14 "2021-04-14T21:39:33Z")

</div>

Thanks for the example Rory! The instrument doesn’t seem to be working properly for me however, even though I have the latest version of Cabbage installed. Here’s what happens on my end:

---

<div class="post-metadata">

**Author:** ![rorywalsh](https://forum.cabbageaudio.com/user_avatar/forum.cabbageaudio.com/rorywalsh/32/165_2.png) [@rorywalsh](https://forum.cabbageaudio.com/u/rorywalsh)\
**Post date:** [15 April 2021 08:51 UTC](https://forum.cabbageaudio.com/t/detecting-mouse-hover/2446/15 "2021-04-15T08:51:35Z")

</div>

Sorry @fellusive, I’m not sure why those changes didn’t propagate. Anyhow, I’ve checked the latest build and this code should work fine there. I’d recommend you use the new GUI system, unless you have already completed the development of an instrument, in which case i’d stick with the ident channels, even though you give up some of the new features.

---

<div class="post-metadata">

**Author:** ![fellusive](https://forum.cabbageaudio.com/user_avatar/forum.cabbageaudio.com/fellusive/32/4515_2.png) [@fellusive](https://forum.cabbageaudio.com/u/fellusive)\
**Post date:** [16 April 2021 04:04 UTC](https://forum.cabbageaudio.com/t/detecting-mouse-hover/2446/16 "2021-04-16T04:04:58Z")

</div>

Thanks for the update Rory - I think there’s a problem with `typeface` in this new version however. With `typeface` enabled, the text within widgets such as comboboxes or labels exhibits strange behavior or looks abnormal in size/thickness. Same goes for the text under sliders.

---

<div class="post-metadata">

**Author:** ![rorywalsh](https://forum.cabbageaudio.com/user_avatar/forum.cabbageaudio.com/rorywalsh/32/165_2.png) [@rorywalsh](https://forum.cabbageaudio.com/u/rorywalsh)\
**Post date:** [16 April 2021 05:40 UTC](https://forum.cabbageaudio.com/t/detecting-mouse-hover/2446/17 "2021-04-16T05:40:35Z")

</div>

Thanks, I’ll take a look. My implantation of this seems to have been a little naive 🙄

---

<div class="post-metadata">

**Author:** ![rorywalsh](https://forum.cabbageaudio.com/user_avatar/forum.cabbageaudio.com/rorywalsh/32/165_2.png) [@rorywalsh](https://forum.cabbageaudio.com/u/rorywalsh)\
**Post date:** [16 April 2021 09:38 UTC](https://forum.cabbageaudio.com/t/detecting-mouse-hover/2446/18 "2021-04-16T09:38:13Z")

</div>

Should be fixed now in GIT and available in [Azure](https://dev.azure.com/rorywalsh/cabbage/_build) shortly.

---

<div class="post-metadata">

**Author:** ![fellusive](https://forum.cabbageaudio.com/user_avatar/forum.cabbageaudio.com/fellusive/32/4515_2.png) [@fellusive](https://forum.cabbageaudio.com/u/fellusive)\
**Post date:** [16 April 2021 19:02 UTC](https://forum.cabbageaudio.com/t/detecting-mouse-hover/2446/19 "2021-04-16T19:02:45Z")

</div>

Thanks for the update again - while the text issues in comboboxes and sliders seem to be fixed, the text in labels with `typeface` enabled still causes it to display strangely. Like characters missing, and random amounts of space in between characters.

---

<div class="post-metadata">

**Author:** ![rorywalsh](https://forum.cabbageaudio.com/user_avatar/forum.cabbageaudio.com/rorywalsh/32/165_2.png) [@rorywalsh](https://forum.cabbageaudio.com/u/rorywalsh)\
**Post date:** [16 April 2021 21:08 UTC](https://forum.cabbageaudio.com/t/detecting-mouse-hover/2446/20 "2021-04-16T21:08:28Z")

</div>

I was seeing that too, but this change seemed to fix that for me? I’ll take another look tomorrow. Thanks for your patience 👍

[Next page](https://forum.cabbageaudio.com/t/detecting-mouse-hover/2446.md?page=2)
