Clicked vs Pressed (Solution and documentation excerpt on how to use and reference Global Variables included within)

Can someone explain the difference to me? They both seem to work exactly the same and I’m trying ti understand the advantage of using one over the other.

in fact, when testing the Pressed event0 in the designer, it actually triggers when released (which seems counter intuitive given there is a released event as well).

Clicked is used more typically. You can create an event for pressed and another event for when it is released. I personally don’t use pressed/released to control any devices but I use it to manipulate the properties of a button to show when I’m pushing it.

Example would be if you had two images of a button- One image is of the button and the other image is of that button where it appears to be pressed down. Using the pressed/released, you can switch between the two images.

So it’s only useful for images?

Images was just an example. You can use it to send commands, change properties, or whatever else you do with eventtriggers

That’s the thing I mentioned in my top post…when I hold the button, it still triggers right away. So I can’t see any difference.

What would be ideal is to have a way to configure a delay…so if pressed for more than x seconds, then…

EDIT: Just realized I had a brain fart when posting this question. Title should have read “Clicked vs Pressed” not “Pressed vs Released.”. I’ve fixed that.

Ah OK. Not really sure of a difference. If you want to use the repeat function you’ll need to use “clicked”.

The Pressed/released events are sent when the button is pressed/released, respectively. Click event is sent only when the button is pressed. In some other environments, Click is sent only when released, not when pressed. I believe THR uses the pressed event to send the click instead of the released event.

One reason to use the pressed/released events is to measure the time difference between the pressed and released events, allowing the procedure to determine if the user long pressed the button (and do something different).

Is there a working example you can share or point me to? This is exactly what I was hoping to accomplish (was a thing back in the iRule days). However, previous discussions suggested it wasn’t possible to do this… Thus, the feature requests that some of us have submitted.

I have not (yet) done this in THR, but I have on other apps. It should be doable in THR though, but you will need to use Javascript and create a THR global variable.

Essentially, in the pressed event, save the current time in milliseconds to that global variable. In the released event, fetch that global variable (and zero it out), compare that time to the current time, and decide if the duration is a short or long press. You can experiment to see what time duration you want for the long press.

Yeah that would work. Kinda clumsy though. Too bad it can’t be native to the event configuration.

That method is exactly how the “native” button code does it. It just appears more eloquent since it is hidden from the user.

Yes…some things should just work.

With this solution, one would need to effectively set up a custom variable for each button. That seems to be a lot more overhead for the user than necessary.

To each their own, I guess.

This may be just beating a dead horse, but I like to correct faulty assumptions.

Are you planning on long pressing more that one button at a time? Assuming not, just reuse that global (which is why I suggest zeroing it out in the release event).

I do something very similar in Tasker to allow double clicks on Widget icons. it works quite well, and I only use two global variables used by all icons (the time and the button I am working on, in case the user presses another button instead).

BTW - I fully agree this capability should be at a lower level, but when you really, really need it, you can make it work.

I’m not going to argue with you any further on this. But in the spirit of developing a tangible solution, I started to look into actually building it out.

  1. My first thought was to use a script action to set/retrive. As I understood, that script actions were discouraged (e.g. the pop-up warning)
  2. I considered using a condition with some basic time math on the trigger for the release action (to keep it simple) but that doesn’t allow for javascript.

So what it looks like I would need to do is:

  • Set a variable for when a button was pressed (pressed action, 1st script)
  • Set a 2nd boolean variable to show the state based on date math (released action, 2nd script) and use that 2nd variable as a condition for the Released action, or
  • Use the release action script to trigger the required event based on the boolean state

If anyone has actually done this, I would appreciate knowing how you approached this and seeing your project/code. One specific gap in my knowledge is how to set a Virtual device variable from within a script. I could use MQTT and Node Red like I usually do to overcome challenges, but given the precise timing needed, I don’t want to introduce any unnecessary delays associated with calling (and the timely execution) of remote services.

No one can help me even with setting a Virtual Device variable from within a script? (or show me where that documentation lives, as I’ve searched without success).

@aa6vh It would seem like the original path has hit a dead end. Can you at least point me to how to create a shared variable in javascript in THR like you suggested is possible? I can handle the rest. TY.

Sorry for the delay in response.

My Onkyo receiver has a weird thing where I have to halve the volume value from the device to match the display. So when I increment the volume, I halve the volume value, and place it in the global variable “Volume”, as follows in the following javascript:

var vol = (App.GetDeviceAttribute(“TxRz810Main.Volume”) +1)/ 2;
App.SetDeviceAttribute(“Volume”, vol);

I think you use the App object similarly for other attributes.

Hope this helps
.

1 Like

It does thx. Is “Volume” the name of the entity created under Virtual Devices? If not, did you have to create / declare it anywhere in order to use it?

(Terminology is tough for me :slight_smile: )

As I stated, “Volume” is the name of a global variable, not a virtual device. I am not near my system that has THR installed, and I probably won’t until this weekend, but as I recall, I think you can create global variables by right clicking on the global variables entity.

Depending on your usage, a global variable might be more useful that a virtual device anyway.

1 Like

I think you can create global variables by right clicking on the global variables entity.

Thanks - I had no idea this even existed. I’ll have a look.