Hack Forums
[C] Why isn't this Working? - Printable Version

+- Hack Forums (https://hackforums.net)
+-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444)
+--- Forum: Coding (https://hackforums.net/forumdisplay.php?fid=151)
+---- Forum: Software Development (https://hackforums.net/forumdisplay.php?fid=118)
+---- Thread: [C] Why isn't this Working? (/showthread.php?tid=5864898)



Why isn't this Working? - F.A.S.T - Jul 22, 2018

Soo, The code below is supposed to print out whenever the keys defined are pressed.
But the opposite happens.

It does not print out the keys pressed, Instead, Only default.

Also, Flush(); is just a function that prints out on the screen.

PHP Code

<?php 
int main
()
{
    
char ikey = 0;
    
//string data = to_string(ikey);
    
while (true) {
        switch (
GetAsyncKeyState(ikey)) {
        case 
up:
            
flush("[UP]");
            break;
        case 
down:
            
flush("[DOWN]");
            break;
        case 
left:
            
flush("[LEFT]");
            break;
        case 
right:
            
flush("[RIGHT]");
            break;
        default:
            
flush("[UNKNOWN-KEY-PRESSED]");
            break;
        }
    }
    return 
0;
} 



RE: Why isn't this Working? - aeiro - Jul 22, 2018

(Jul 22, 2018 10:46 AM)F.A.S.T Wrote:  Soo, The code below is supposed to print out whenever the keys defined are pressed.
But the opposite happens.

It does not print out the keys pressed, Instead, Only default.

Also, Flush(); is just a function that prints out on the screen.

PHP Code

<?php 
int main
()
{
 
char ikey = 0;
 
//string data = to_string(ikey);
 
while (true) {
 switch (
GetAsyncKeyState(ikey)) {
 case 
up:
 
flush("[UP]");
 break;
 case 
down:
 
flush("[DOWN]");
 break;
 case 
left:
 
flush("[LEFT]");
 break;
 case 
right:
 
flush("[RIGHT]");
 break;
 default:
 
flush("[UNKNOWN-KEY-PRESSED]");
 break;
 }
 }
 return 
0;
} 
the GetAsyncKeyState function parameter must have one of the Virtual_KEY codes documented here
https://docs.microsoft.com/en-us/windows/desktop/inputdev/virtual-key-codes