Press Enter Twice - Page 2
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 2 of 2 FirstFirst 12
Results 16 to 24 of 24

Thread: Press Enter Twice

  1. #16
    Join Date
    Nov 2000
    Location
    Voronezh, Russia
    Posts
    5,931

    Re: Press Enter Twice

    You need to understand the code you write. Precisely, what count means and how it differs from pressCount.

    Then you need to think about exact meaning of "press Enter twice". If you press Enter and wait 24 hours before pressing Enter second time, will it be two "single presses" or a single "press twice"? Your code tells me the second is true. Now you tell yourself whether it is.
    Best regards,
    Igor

  2. #17
    Join Date
    Jul 2009
    Location
    India
    Posts
    835

    Re: Press Enter Twice

    if (count != 0)

    where did you defined count ?

  3. #18
    Join Date
    May 2010
    Posts
    8

    Re: Press Enter Twice

    Sry, but this code wont work I try
    Code:
    switch( Key )
      {
       case  'VK_RETURN':
       { 
          pressCount = ++pressCount % 2 }
          if (pressCount != 0)
          {
             //first time
          }
          else
          {
             //second time
             pressCount = 0;
          }
    
       break;
    And
    Code:
    int pressCount = 0;
    switch( Key )
      {
       case 'VK_RETURN:
       {
          if (pressCount == 0)
          {
             //first time
             ++pressCount;
          }
          else
          {
             //second time
             pressCount = 0;
          }
        }
       break;
    No one will work

  4. #19
    Join Date
    May 2010
    Posts
    8

    Re: Press Enter Twice

    Pls somebody help :/

  5. #20
    Join Date
    Nov 2000
    Location
    Voronezh, Russia
    Posts
    5,931

    Re: Press Enter Twice

    No one will work
    ... until you make pressCount be static.
    Best regards,
    Igor

  6. #21
    Join Date
    May 2010
    Posts
    8

    Re: Press Enter Twice

    Finally I figure out how to solve this problem, thank you Igor

  7. #22
    Join Date
    Nov 2000
    Location
    Voronezh, Russia
    Posts
    5,931

    Re: Press Enter Twice

    You're welcome.
    Best regards,
    Igor

  8. #23
    Join Date
    Apr 2008
    Posts
    726

    Re: Press Enter Twice

    count isnt defined anywhere (in scope or in class declaration)

  9. #24
    Join Date
    Jul 2009
    Location
    India
    Posts
    835

    Re: Press Enter Twice

    If still not solved here is code snippet.

    Code:
    BOOL CTESDlg::PreTranslateMessage(MSG* pMsg)
    {
    	static int co = 0;
    
    	if (pMsg->message == WM_KEYDOWN && pMsg->wParam == VK_RETURN)
    	{
    		pMsg->wParam = NULL;
    		++co;
    
    		if (co==2)
    			AfxMessageBox(L"Twice Pressed");
    	}
    	
    	return CDialog::PreTranslateMessage(pMsg);
    }

Page 2 of 2 FirstFirst 12

Tags for this Thread

Posting Permissions

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


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center