hi i have two problems in c++ console application


1. I want a function to execute when a certain key is pressed .kbhit() is for any key but i want to modify it to a specific key ..plz tell me about it also if any other function can do this


2.i want to retrieve the x and y coordinates of of an object...how can i do this

kbhit() is for any key but i want to modify it to a specific key ..

kbhit() tells you if a key has been pressed. You can then use getch() to determine the value of the key.

i want to retrieve the x and y coordinates of of an object...how can i do this

Please specify what you mean by an "object".

thanks Narue for ur reply

can u plz tell how to use kbhit withi getch()


object means any character

can u plz tell how to use kbhit withi getch()

if (kbhit() && getch() == character_you_want) {
    // Yay!
}

object means any character

Well, you can manually keep a copy of the visible screen in memory. I don't think the conio.h library supports extracting already written characters even on Borland compilers. Your next step if you don't want to maintain your own copy of the screen is to use a library such as PDCurses which have the functionality you want (the inch() functions in particular for curses variants).

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.