-
July 2nd, 2007, 06:49 AM
#1
action on pressing a key
hi
i am having an experiment with sensors. I calcualte the current distance top be d0 & print it out. But i need to get a reference point
So i want to set a reference point everytime i press a key& the distance then has to be caluculated
with "dref - do" .... & this " new" current distance has to be given out.Does anyone have ideas for the syntax !
thanks
Code:
case WM_PAINT:
...
...
d0 = s[1].d + (z_[0] * ( s[2].d - s[1].d )) + (z_[1] * ( s[3].d - s[1].d )) + (z_[2] * ( s[4].d - s[1].d ) )+ (z_[3] * ( s[5].d - s[1].d ));
y += CharHeight*2; /* Print */
sprintf (OutString,"d current = %lf ", d0);
TextOut(hDC, x, y, OutString, strlen (OutString));
SetTextAlign(hDC, TA_LEFT | TA_TOP);
EndPaint(hWndMain, &ps);
break;
case WM_KEYDOWN:
if (wParam == 'A') {
}
-
July 2nd, 2007, 07:48 AM
#2
Re: action on pressing a key
Initially set a reference point to your global static variable before you read the sensor data.
Then afterwards, use timer or threads to read keyboard input from the user to get a new reference value.
Always show the (Distance - Ref) on the screen.
Is this what you are looking for.
Please explain clearly
Dan
-
July 2nd, 2007, 07:59 AM
#3
Re: action on pressing a key
Originally Posted by danandu
Initially set a reference point to your global static variable before you read the sensor data.
Then afterwards, use timer or threads to read keyboard input from the user to get a new reference value.
Always show the (Distance - Ref) on the screen.
Is this what you are looking for.
Please explain clearly
No . Let me try again :-)
Now i am giving out "d0" continuously on the screen. At a certain point i would like to save a particular value of d0 as my reference value"dref"by pressing a key.
The value that i would then like to output on the screen is "d0-dref"
where d0 is the values which i get continuooulsly & was shwoing earlier on teh screen & dref is the value i saved by pressing the key .
-
July 2nd, 2007, 08:39 AM
#4
Re: action on pressing a key
Handle the WM_KEYDOWN event and store the immediate value of d0 into a static dref.
Then from thereon, set a flag that a new ref has come.
Then always based on the flag's value
if flag is present
output d0 - dref
else
output d0 // only
...Also if you don't want to use the flag set dref initially to 0 and output always d0 - dref
simple!
Dan
-
July 2nd, 2007, 08:47 AM
#5
Re: action on pressing a key
thanks ! i think i will do it the second way ... first dref to 0 & then give dref a value...
but one question ; how should the key case look :
Like this ??
[code]
case WM_KEYDOWN:
if (wParam == 'A') {
d0 = dref ;
}
[code]
-
July 2nd, 2007, 09:38 AM
#6
Re: action on pressing a key
Nobody cares how it works as long as it works
-
July 2nd, 2007, 01:25 PM
#7
Re: action on pressing a key
hm ... this still does not work ... any suggestions ... ??
Code:
float dn,dref = 0;
dn = d0-dref;
d0 = s[1].d + (z_[0] * ( s[2].d - s[1].d )) + (z_[1] * ( s[3].d - s[1].d )) + (z_[2] * ( s[4].d - s[1].d ) )+ (z_[3] * ( s[5].d - s[1].d ));
y += CharHeight*2;
sprintf (OutString,"d current = %lf ", dn);
TextOut(hDC, x, y, OutString, strlen (OutString));
case WM_KEYDOWN:
if (wParam == 'A') {
dref = d0;
}
-
July 3rd, 2007, 02:19 AM
#8
Re: action on pressing a key
still not working ... does anyone have an idea ??
my prob again ::
Now i am giving out "d0" continuously on the screen. At a certain point i would like to save a particular value of d0 as my reference value"dref"by pressing a key.
The value that i would then like to output on the screen is "d0-dref"
where d0 is the values which i get continuooulsly & was shwoing earlier on teh screen & dref is the value i saved by pressing the key .
-
July 3rd, 2007, 02:36 AM
#9
Re: action on pressing a key
Which project is this? is it a console project or an Win32 Application project.
You should handle the WM_KEYDOWN message from windows message handler which are available in the class wizard of MFC.
If you are using Win32, see MSDN to handle WM_KEYDOWN.
Dan
-
July 3rd, 2007, 02:43 AM
#10
Re: action on pressing a key
thanks i will try there. but isnt this the "WM_KEYDOWN" from msdn ?? i was just not sure what has to be written inside the Keydown ... i have called it from my winmessagehandler ...
-
July 3rd, 2007, 02:51 AM
#11
Re: action on pressing a key
Dan
-
July 3rd, 2007, 02:54 AM
#12
Re: action on pressing a key
Last edited by sdherzo; July 3rd, 2007 at 08:58 AM.
-
July 3rd, 2007, 09:01 AM
#13
Re: action on pressing a key
hm .. i am doing something wrong i teh message handler ... i tried the method suggested by u & set d = d0- dref & set dref initially to 0 & put dref = d0 in the KEYDOWN message habndler ... still doesnt react on pressing the key
anyone sees the mistake ??
Code:
float dref = 0 ;
case WM_PAINT:
{
d0 = ...;
dn = (d0) - (dref);
y += CharHeight*2;
sprintf (OutString,"d current = %lf ", dn);
TextOut(hDC, x, y, OutString, strlen (OutString));
}
case WM_KEYDOWN:
if (wParam == 'A')
{
dref = d0;
}
-
July 3rd, 2007, 09:14 AM
#14
Re: action on pressing a key
You need a break statement after each case in the switch...case block.
Code:
case WM_PAINT:
...
...
break;
case WM_KEYDOWN:
...
...
break;
Nobody cares how it works as long as it works
-
July 3rd, 2007, 09:16 AM
#15
Re: action on pressing a key
i have a break ... just didnt post it here as i just wanted to post the important part of the code ;-) The problem lies inside my WM_KEYDOWN i think
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|