Page 1 of 1

I just cant see the answer...

Posted: Tue Jan 27, 2015 9:54 pm
by solidelectricalltd
Its going to be glaringly obvious but I just cant see the solution, looking at it too deep maybe. I want to put a power off button on a press/hold so you press and hold it for say 3 seconds and runs a macro but if you let go before 3 seconds it doesn't do anything.

Come on peeps, I'm tearing my hair out.

Cheers.

Re: I just cant see the answer...

Posted: Wed Jan 28, 2015 6:28 am
by Idealhomes
I would do it using a flags based on time.

When a button is pressed, a flag (you could call it 'power off ready') goes on at 2.55 secs and off at 3.20 secs (using a delay for times), then set the button release to execute your commands but only if 'power off ready' is on using the 'Dependent Flag'. This will allow you to execute your macros at the 3 second mark, any earlier and they will not execute but the flag will reset for next time.

Simple but effective. I hope this helps :)

Re: I just cant see the answer...

Posted: Wed Jan 28, 2015 6:45 pm
by cv27
Idealhomes wrote:I would do it using a flags based on time.

When a button is pressed, a flag (you could call it 'power off ready') goes on at 2.55 secs and off at 3.20 secs (using a delay for times), then set the button release to execute your commands but only if 'power off ready' is on using the 'Dependent Flag'. This will allow you to execute your macros at the 3 second mark, any earlier and they will not execute but the flag will reset for next time.

Simple but effective. I hope this helps :)
I suspect if I hold the button for more than the Off delay, the actions won't fire?

Re: I just cant see the answer...

Posted: Wed Jan 28, 2015 6:56 pm
by cv27
solidelectricalltd wrote:Its going to be glaringly obvious but I just cant see the solution, looking at it too deep maybe. I want to put a power off button on a press/hold so you press and hold it for say 3 seconds and runs a macro but if you let go before 3 seconds it doesn't do anything.

Come on peeps, I'm tearing my hair out.

Cheers.
Here's another approach.

1- On the press event of a button, set a flag to OFF (flag name "button_hold" for example)
2- Also in the press event, set flag "button_hold" to On after a delay of 3 seconds
3- On the release event of that button, perform your actions, all being dependent on flag "button_hold" being On

If your list of actions is on the long side, you might want to create those in a macro (number custom actions) and then just set that number to 1 in the release event depending on flag "button_hold" being On.

Re: I just cant see the answer...

Posted: Wed Jan 28, 2015 7:34 pm
by Idealhomes
cv27 wrote:
Idealhomes wrote:I would do it using a flags based on time.

When a button is pressed, a flag (you could call it 'power off ready') goes on at 2.55 secs and off at 3.20 secs (using a delay for times), then set the button release to execute your commands but only if 'power off ready' is on using the 'Dependent Flag'. This will allow you to execute your macros at the 3 second mark, any earlier and they will not execute but the flag will reset for next time.

Simple but effective. I hope this helps :)
I suspect if I hold the button for more than the Off delay, the actions won't fire?
Yeah doing it this way will only give you a window of opportunity for the macro to fire, or you can have the flag go off on the release press instead of timed delay.

Press button: Set flag 'power off ready' with delay of 2.55 seconds

Release button: Fire Macro dependant on 'power off ready' being 'On', and then set 'power off ready' flag to 'Off' (making sure this is at the bottom of the list).

Re: I just cant see the answer...

Posted: Wed Jan 28, 2015 10:04 pm
by cv27
solidelectricalltd wrote:Its going to be glaringly obvious but I just cant see the solution, looking at it too deep maybe. I want to put a power off button on a press/hold so you press and hold it for say 3 seconds and runs a macro but if you let go before 3 seconds it doesn't do anything.

Come on peeps, I'm tearing my hair out.

Cheers.
The issue with my first proposed approach is that the user sees no feedback until the button is released; he may have pressed & held the button for 5-6 seconds for nothing. So here's a variation:
0- To use this, you need to put all your actions in a macro (custom number actions); let's assume Exec_Off as a number
1- On the press event of a button, set a flag to OFF (flag name "button_hold" for example)
2- Also in the press event, set flag "button_hold" to On after a delay of 3 seconds
3- On the press & hold event of that button, set Exec_Off = 1, dependent on flag "button_hold" being On and set to repeat every 3.1 seconds
4- Nothing on the release event of the button
5- To avoid the user pressing & holding the button for ever and re-engaging the custom number actions more than once, set "button_hold" to Off as the first action in your custom number actions

With this version, the user will see the actions immediately at 3 seconds, so he knows to let go the button.

Re: I just cant see the answer...

Posted: Thu Jan 29, 2015 9:51 am
by solidelectricalltd
Thanks a bunch chaps, much appreciated. You are life savers.

Re: I just cant see the answer...

Posted: Fri Jan 30, 2015 6:40 am
by Idealhomes
cv27 wrote:
solidelectricalltd wrote:Its going to be glaringly obvious but I just cant see the solution, looking at it too deep maybe. I want to put a power off button on a press/hold so you press and hold it for say 3 seconds and runs a macro but if you let go before 3 seconds it doesn't do anything.

Come on peeps, I'm tearing my hair out.

Cheers.
The issue with my first proposed approach is that the user sees no feedback until the button is released; he may have pressed & held the button for 5-6 seconds for nothing. So here's a variation:
0- To use this, you need to put all your actions in a macro (custom number actions); let's assume Exec_Off as a number
1- On the press event of a button, set a flag to OFF (flag name "button_hold" for example)
2- Also in the press event, set flag "button_hold" to On after a delay of 3 seconds
3- On the press & hold event of that button, set Exec_Off = 1, dependent on flag "button_hold" being On and set to repeat every 3.1 seconds
4- Nothing on the release event of the button
5- To avoid the user pressing & holding the button for ever and re-engaging the custom number actions more than once, set "button_hold" to Off as the first action in your custom number actions

With this version, the user will see the actions immediately at 3 seconds, so he knows to let go the button.
Or....lol, there are many ways to do this....

Press button: sets flag 'Power Off Ready' to 'ON' with no delays, have a delay of 3 seconds that executes your Macros with 'Dependant Flag' 'Power Off Ready' being 'ON'.

Release button: sets flag 'Power Off Ready' to 'OFF'.

Actions will always execute at 3 seconds as long as you do not release the button, you will always see feedback at the 3 second mark even if you hold for 4+ seconds.

Who else has a way to do this..... :lol:

Re: I just cant see the answer...

Posted: Fri Jan 30, 2015 6:32 pm
by cv27
Idealhomes wrote:Or....lol, there are many ways to do this....

Press button: sets flag 'Power Off Ready' to 'ON' with no delays, have a delay of 3 seconds that executes your Macros with 'Dependant Flag' 'Power Off Ready' being 'ON'.

Release button: sets flag 'Power Off Ready' to 'OFF'.

Actions will always execute at 3 seconds as long as you do not release the button, you will always see feedback at the 3 second mark even if you hold for 4+ seconds.

Who else has a way to do this..... :lol:
SO funny, reminds me of my early programming days where we had contests for who could code a function with the least amount of code :ugeek:

On this one, Idealhomes, you get the prize