#using keyboard input

19 messages · Page 1 of 1 (latest)

chilly cradle
#

why does pressing backspace break the program

int main() {
    while(1){
        if(_kbhit()){
            if (GetAsyncKeyState(0x0D)){
                Item rolled = weighted_random_choice(items,weights);
                std::cout<<"you rolled a "<<rolled.getName()<<" ("<<rolled.getRarity()<<")\n";
                Sleep(1000); continue;
            }
            else if (GetAsyncKeyState(0x08)) return 0;
        }
        Sleep(10);
    }
}
short bayBOT
#

When your question is answered use !solved to mark the question as resolved.

Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question use !howto ask.

rotund quest
#

consider using the macros defined by windows in GetAsyncKeyState() 0x0D isnt very readable

#

its VK_KEYNAME btw

#

for letters its the asci number so you can just do 'a' for example

chilly cradle
#

like VK_BACK ?

rotund quest
#

next time also try to only send relevent code

#

which GetKeyStateAsync is backspace?

chilly cradle
rotund quest
#

you return...

#

returning from main exits the application

chilly cradle
#

that's what it's supposed to do

rotund quest
#

then whats broken?

chilly cradle
#

it doesnt exit

rotund quest
#

try using {} and exit(0); to exit

#

I have to go now hope this helped

chilly cradle
#

ok

#

!solved