Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472
[phpBB Debug] PHP Notice: in file /includes/functions.php on line 3368: Cannot modify header information - headers already sent by (output started at /includes/bbcode.php:472)
[phpBB Debug] PHP Notice: in file /includes/functions.php on line 3370: Cannot modify header information - headers already sent by (output started at /includes/bbcode.php:472)
[phpBB Debug] PHP Notice: in file /includes/functions.php on line 3371: Cannot modify header information - headers already sent by (output started at /includes/bbcode.php:472)
[phpBB Debug] PHP Notice: in file /includes/functions.php on line 3372: Cannot modify header information - headers already sent by (output started at /includes/bbcode.php:472)
OrbWorks Community Forum • View topic - Button Question

Button Question

A PocketC native palm library offering native forms and assorted utilities

Postby stefangrove on Thu Aug 21, 2003 1:30 pm

Hi

Is there any way to test if a button is being pressed (held down)? Or maybe measure how long it was held down for?

Stef
stefangrove
 
Posts: 24
Joined: Fri Dec 06, 2002 10:43 am
Location: Austria

Postby jstadolnik on Thu Aug 21, 2003 1:45 pm

You can use the Fctl TRIGTIME (#401) command to get the system time when a button was intially pressed.

This feature allows you to construct buttons which behave differently if held down for a period of time. I saw SyPDA do this in an app. He also put a dot in the button text to indicate it as having this special functionality. It's a good trick.

e=Fevent(1);
if(e==MYBUTTON) {
if((ticks()-Fctl(TRIGTIME))>100) {
//button held down for 1 second or more
}
else {
//normal button functionality
}
}

Joe

The PToolboxLib guy.
http://www.geocities.com/retro_01775/PToolboxLib.htm
jstadolnik
 
Posts: 1741
Joined: Wed Dec 06, 2000 3:34 am
Location: USA

Postby stefangrove on Sat Aug 23, 2003 10:31 am

Fctl(401) works perfectly the first time I call it, but on the second call it gives the same value as the first time. Thus, the second time I press the button, it is interpreted as if I was holding it down since the first time I started to press it.
stefangrove
 
Posts: 24
Joined: Fri Dec 06, 2002 10:43 am
Location: Austria

Postby jstadolnik on Sat Aug 23, 2003 2:27 pm

Fctl TRIGTIME should return the time of the initial pen down event in the last button pressed.

The code behind this feature is extremely simple and I cannot see any way for it to fail. So I suspect that you have a bug in your code. Like maybe you're missing a switch-case break somewhere?

Below is an example of its use. If this doesn't make sense I would suggest posting your code in question.

Joe

-- ----------------

//holdbuttons.pc
library "PToolboxLib"
include "Fctl.h"

#define FORM1 3000
#define FIELD1 3001
#define BUTTON1 3002
#define BUTTON2 3003
#define BUTTON3 3004
#define BUTTON4 3005
#define DONE 3006

main() {
int x,e;
Form(FORM1,"Hold Button Demo");
Field(FIELD1,0x100,0,40,160,0,80,"Tap or hold & release the buttons");
x=Button(BUTTON1,0,20,100,0,0,BUTTON1);
x=Button(BUTTON2,0,x,100,0,0,BUTTON2);
x=Button(BUTTON3,0,x,100,0,0,BUTTON3);
x=Button(BUTTON4,0,x,100,0,0,BUTTON4);
Button(DONE,0,1,145,0,0,"Done");
Fctl(DRAW,FORM1);
while(1) {
e=Fevent(1);
switch(e) {
case DONE: return;
case BUTTON1: case BUTTON2: case BUTTON3: case BUTTON4:
if((ticks()-Fctl(TRIGTIME))>100) {
FsetText(FIELD1,"Button "+e+" was held down >100 ticks");
}
else {
FsetText(FIELD1,"Button "+e+" was tapped");
}
break;
}
}
}


The PToolboxLib guy.
http://www.geocities.com/retro_01775/PToolboxLib.htm
jstadolnik
 
Posts: 1741
Joined: Wed Dec 06, 2000 3:34 am
Location: USA

Postby stefangrove on Sun Aug 24, 2003 12:34 pm

I found the problem and it somehow connects to my earlier question about event() and Fevent().

1. while (!out){
2. event(1);
3. evnt=Fevent(1);
4.
5. if (evnt==playbutton){
6. now=ticks();
7. then=Fctl(401,0);
8. aduration=500;
9. if ((now-then)>100)
10. aduration=3000;

100. }}

As it was, the value of 'then' did not change after the first completion of the loop, (causing the second button press being recorded as being held down for ages) but as soon as I removed the line, everything worked like a faery tale. I originally included it BECAUSE it would not register any button presses, so that pen actions from the functions in the loop would be cleared and buttons would not be pressed unintentionally.

My functions are littered with bits like

event(20);
event(20);

to prevent pen events from being processed twice. Is there a better way of prevention?

Stef.
stefangrove
 
Posts: 24
Joined: Fri Dec 06, 2002 10:43 am
Location: Austria

Postby jstadolnik on Sun Aug 24, 2003 1:14 pm

The reason why your app is misbehaving is because you are mixing event() and Fevent() in the same loop. NEVER mix these in the same loop else you can spend hours chasing down strange behavior.

event() will steal events from Fevent(), causing Fevent to miss events it needs to work correctly. In your case, event() is stealing the button enter event before Fevent() even sees it, preventing Fevent() from recording the button enter time.

Try replacing all your event() calls with Fevent() and see what happens. For example, remove line #2 from your code entirely.

<blockquote id="quote"><font size="1" face="Verdana, Arial, Helvetica" id="quote">quote:<hr height="1" noshade id="quote">
My functions are littered with bits like

event(20);
event(20);

to prevent pen events from being processed twice. Is there a better way of prevention?
<hr height="1" noshade id="quote"></blockquote id="quote"></font id="quote">

I don't quite understand why you need these in the first place. What happens if you remove these altogether?

Joe


The PToolboxLib guy.
http://www.geocities.com/retro_01775/PToolboxLib.htm
jstadolnik
 
Posts: 1741
Joined: Wed Dec 06, 2000 3:34 am
Location: USA


Return to Pocket Toolbox

Who is online

Users browsing this forum: No registered users and 2 guests

cron