Click here to Skip to main content
15,907,329 members
Please Sign up or sign in to vote.
2.00/5 (2 votes)
See more:
C#
string keystroke(char KeyStroke, string output2){

    while (true==true) {
        KeyStroke = getch();
        if (KeyStroke == 0)
        {
            KeyStroke = getch(); // Even though there are 2 getch() it reads one keystroke
            switch (KeyStroke)
            {
            case UP_ARROW:
                Keystroke1 = "up";
                charpos_calculation(Keystroke1);
            break;
            }
        }
    }
    return output2;
}


_____________________________________________________________________________________________

Question 1 - When ran my program returns this error .The POSIX name for this item is deprecated
What do I need to do to fix this.

Question 2 - How do I get a keystroke? I defined the up arrow by #define UP_ARROW 25. Is this the right way and the right value.

What I'm trying to figure out is how to get direct keyboard input from the user. How would I do this so the user doesn't have to press enter.

This is a console application using Windows Visual Studio 2012 Express.

Also this is part of my code of a larger game.
Posted
Comments
Ron Beyer 7-Jan-14 17:04pm    
Please update your question with the code that includes the error for the POSIX issue. The above doesn't have anything dealing with POSIX threads. Its difficult to identify a solution if we don't have all the information.
Member 10506844 7-Jan-14 17:19pm    
Visual Studio points the error I displayed above to the above code. If that is not it, I don't know what it would be. How many lines of code can i paste into my question because I have 700.

1 solution

Quote:
Question 1 - When ran my program returns this error .The POSIX name for this item is deprecated
What do I need to do to fix this.
I believe that is a warning, not an error. Anyway the compiler is right, of course :-), see the documentation[^] for a fix (that is use _getch[^] instead).



Quote:
Question 2 - How do I get a keystroke? I defined the up arrow by #define UP_ARROW 25. Is this the right way and the right value.
You may test it.
 
Share this answer
 
Comments
Member 10506844 7-Jan-14 17:35pm    
When I use the KeyStroke = _getch. I get this error. IntelliSense: a value of type "int (__cdecl *)()" cannot be assigned to an entity of type "char". What do I need to do to fix this.
CPallini 7-Jan-14 17:38pm    
You missed the braces:
KeyStroke = _getch();
Member 10506844 7-Jan-14 17:57pm    
Sorry for my stupidity.
CPallini 7-Jan-14 18:09pm    
Just an oversight, I believe.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900