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:
1
2
3
4
5
6
7
8
void __fastcall TForm1::ListBox1KeyPress(TObject *Sender, char &Key)
{
switch( Key )
  {
   case  'VK_RETURN':
   { atidarytpav(); }
   break;
}
You would need to pass into a second control loop. Or have a variable that counts the number of key presses with in that "case". You could have a function with in the case that tests to see if the picture is already open, if TRUE then play music. There are a bunch of ways to do this.
Can you show me a small example?
Ok I have this script
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
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

 
Undefined symbol 'count'

Do I need some library or what .. ?
Maybe line 11 should read if (pressCount != 0) Otherwise in this snipit of code I don't see where you declared "count" as a variable.

EDIT: I can't remember if having the if else outside of the case statement will mess with your program, I would move it inside if you see anything out of what you expect.
Last edited on
@Computergeek01,
The if/else is inside the case statement.
Huh, so it is, I wonder what it was I saw before. I guess it doesn't matter now, does she work?
Sry Guys, but this code wont work I try
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
switch( Key )
  {
   case  'VK_RETURN':
   { 
      pressCount = ++pressCount % 2 }
      if (pressCount != 0)
      {
         //first time
      }
      else
      {
         //second time
         pressCount = 0;
      }

   break;


And
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
int pressCount = 0;
switch( Key )
  {
   case 'VK_RETURN:
   {
      if (pressCount == 0)
      {
         //first time
         ++pressCount;
      }
      else
      {
         //second time
         pressCount = 0;
      }
    }
   break; 

No one will work
Last edited on
Pls somebody help :/
Won't your program always detect the first time you hit the 'enter' key and act accordingly? Think about mouse clicks for a second. The computer won't wait forever to see if you want to click once or twice. It will wait for a set period of time. You should have a time lapse after the first key stroke, after which the computer will process the desired selection. Let me try to explain in pseudocode:

if enter is pressed
start timer
if enter is pressed while timer is running
start music
else
open picture


Or you could just assign different keys to each function.

I hope this is helpful.
Finally I figure out how to solve this problem, thank you Davitosan
Topic archived. No new replies allowed.