dcsimg
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 15 of 40

Thread: action on pressing a key

Hybrid View

  1. #1
    Join Date
    Apr 2007
    Posts
    75

    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') {
    
    
    }

  2. #2
    Join Date
    May 2005
    Posts
    364

    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

  3. #3
    Join Date
    Apr 2007
    Posts
    75

    Re: action on pressing a key

    Quote 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 .

  4. #4
    Join Date
    May 2005
    Posts
    364

    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

  5. #5
    Join Date
    Apr 2007
    Posts
    75

    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]

  6. #6
    Join Date
    Jun 2002
    Location
    Stockholm, Sweden
    Posts
    1,641

    Re: action on pressing a key

    the other way,

    Code:
    dref = d0;
    imho
    Nobody cares how it works as long as it works

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width




On-Demand Webinars (sponsored)