Press Enter Twice

This is a discussion on Press Enter Twice within the C++ Programming forums, part of the General Programming Boards category; Hi, I`m new here and, of course, have a small problem. I need to create a program with VC++ 6 ...

  1. #1
    Registered User
    Join Date
    Jan 2011
    Posts
    7

    Question Press Enter Twice

    Hi, I`m new here and, of course, have a small problem.
    I need to create a program with VC++ 6 Builder where:
    Press ENTER once - open picture,
    Press ENTER Twice - start a music.

    I can`t figure out how to check if user press ENTER twice, can anybody help me?

    My Code:
    Code:
    void __fastcall TForm1::ListBox1KeyPress(TObject *Sender, char &Key)
    {
    switch( Key )
      {
       case  'VK_RETURN':
       { atidarytpav(); }
       break;
    }

  2. #2
    Registered User
    Join Date
    Dec 2006
    Location
    Scranton, Pa
    Posts
    252
    You could do something as simple as using a control_int, whereas if int_control==1, do this, else (if int_control==2) do something else, then reset int_control back to '0'. It's a simple hack -

  3. #3
    Registered User
    Join Date
    Jan 2011
    Posts
    7
    Can you explaining more or could you give me a very tiny example?

  4. #4
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    How fast do you need to press the enter key? If speed isn't an issue, then you can just, in your VK_RETURN case, count how many times you've been there -- the first time show the picture, the second time play the music, etc.

  5. #5
    Registered User
    Join Date
    Jan 2011
    Posts
    7
    Ok I have this script
    Code:
    int pressCount = 0;
    void __fastcall TForm1::ListBox1KeyPress(TObject *Sender, char &Key)
    {
       
    switch( Key )
      {
       case  'VK_RETURN':
       { 
          atidarytpav(); 
          pressCount = ++pressCount % 2 }
          if (count != 0)
          {
             //first time
          }
          else
          {
             //second time
             pressCount = 0;
          }
    
       break;
    }
    but now say

    Code:
    Undefined symbol 'count'
    Do I need some library or what .. ?

  6. #6
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    You call it pressCount everywhere else, why not that line too?

  7. #7
    Registered User
    Join Date
    Jan 2011
    Posts
    7
    it wont work when i call him there

  8. #8
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    Quote Originally Posted by Alone882 View Post
    it wont work when i call him there
    Of course it will.

  9. #9
    Registered User
    Join Date
    Dec 2006
    Location
    Scranton, Pa
    Posts
    252
    Code:
     if(pressCount!=0){
    
     // do something
    
     }
    How is that going to allow you to ever reach your else statement? pressCount is always going to != 0. You're using odd/even comparative here? I imagine you could, but then there'd be no reason to reset pressCount back to '0'

    more like;

    Code:
     ++pressCount;
    
     if(pressCount<2)
      {
     //do something
      }
    
       else {
    
        //do something else
    
       presCount=0;
     }

  10. #10
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    Quote Originally Posted by Oldman47 View Post
    Code:
     if(pressCount!=0){
    
     // do something
    
     }
    How is that going to allow you to ever reach your else statement? pressCount is always going to != 0. You're using odd/even comparative here? I imagine you could, but then there'd be no reason to reset pressCount back to '0'

    more like;

    Code:
     ++pressCount;
    
     if(pressCount<2)
      {
     //do something
      }
    
       else {
    
        //do something else
    
       presCount=0;
     }
    If pressCount is 1, then ++pressCount % 2 would be 0. I suppose there might be some sequence point issues going on.

  11. #11
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,489
    More waste of effort guys -> Press Enter Twice - C++
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  12. #12
    Registered User
    Join Date
    Jan 2011
    Posts
    7
    Sry Guys, 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

  13. #13
    Registered User
    Join Date
    Jan 2011
    Posts
    7
    Pls somebody help :/

  14. #14
    Registered User
    Join Date
    Jan 2011
    Posts
    7
    Finally I figure out how to solve this problem, thank you

  15. #15
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,538
    This looks like some type of Borland stuff. Firstly, I'd stay away from Borland stuff. It's old. It's oudated.
    Secondly, this forum is more about pure C++ and not what you're asking. You are asking questions about some sort of graphical framework, which does not belong in this forum.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Simple XOR Program
    By dolfaniss in forum C Programming
    Replies: 8
    Last Post: 05-24-2010, 01:27 PM
  2. input function without a need to press Enter?
    By chao06 in forum C Programming
    Replies: 1
    Last Post: 06-19-2009, 03:18 PM
  3. trouble with creating a loop to read certain number of inputs
    By import tuner650 in forum C++ Programming
    Replies: 2
    Last Post: 03-20-2008, 07:28 PM
  4. Einstine calculator
    By Mach_ie in forum C Programming
    Replies: 2
    Last Post: 08-30-2003, 09:37 AM
  5. hi need help with credit limit program
    By vaio256 in forum C++ Programming
    Replies: 4
    Last Post: 03-31-2003, 11:23 PM

Tags for this Thread


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21