Easy A
Would you like to react to this message? Create an account in a few clicks or log in to continue.


 
HomeHome  Latest imagesLatest images  SearchSearch  RegisterRegister  Log inLog in  

Share
 

 "Press any key to continue..."

View previous topic View next topic Go down 
AuthorMessage
Ownage
Member
Member
Ownage

Posts : 9
Join date : 2011-05-20

"Press any key to continue..." Empty
PostSubject: "Press any key to continue..."   "Press any key to continue..." EmptyThu Jul 14, 2011 12:28 am

What can I use to allow a user to just press any key to continue, without having to follow up with hitting enter.

I know I can do getchar() or cin.get(), but those require the enter key be pressed. I also know about getch(), but that it's not ANSI. Also there's system(PAUSE), but heard that comes with a lot of overhead.

I'd like this to work mainly as a C environment as opposed to a C++ environment (if that makes sense). Any suggestions? Thanks
Back to top Go down
Deserve
Member
Member
Deserve

Posts : 7
Join date : 2011-05-11

"Press any key to continue..." Empty
PostSubject: Re: "Press any key to continue..."   "Press any key to continue..." EmptyThu Jul 14, 2011 12:28 am

Easiest way to this I think would be using the ncurses library if you are working in Linux, and I think there is some function under Windows that can accomplish this task too.

I'm thinking out aloud here, but it may be possible to only use the stdio.h library. I would try opening up the stdin stream as a file, and use fseek to point to the end of the stream, and record the position of the pointer. Then print your message and update/check the position of the file pointer again. If it changes then you know the user has typed something in.

EDIT: Nevermind, I realized that this won't work. You still need scanf to update the stdin stream.
Back to top Go down
Deserve
Member
Member
Deserve

Posts : 7
Join date : 2011-05-11

"Press any key to continue..." Empty
PostSubject: Re: "Press any key to continue..."   "Press any key to continue..." EmptyThu Jul 14, 2011 12:29 am

So I thought about this a little it more this morning, and I don't think there is a portable way to do this. Input using the standard io library has to be buffered, so the use of the cartridge return is required.

If you want to achieve this you'll have to play with the keyboard directly. Under Windows this would mean installing a hook to capture keyboard events. Under Linux you can simply use ncurses or use a raw terminal. Or you could just continue using solutions like getch() or kbhit(). Regardless, none of these solutions are standard.

Sorry I couldn't be more help.
Back to top Go down
Ownage
Member
Member
Ownage

Posts : 9
Join date : 2011-05-20

"Press any key to continue..." Empty
PostSubject: Re: "Press any key to continue..."   "Press any key to continue..." EmptyThu Jul 14, 2011 12:29 am

Well thanks for putting on your thinking cap for this one. After further research it would seem you're right. About the only way to do it with things that already exist are the methods I mentioned. Oh well, printing a message that says "...Enter key..." instead of "...Any Key..." probably wouldn't be too big a deal anyway. I would hope people don't get uppity about "ZOMG I have to hit a specific key nooooo!!" Thanks again for your input.
Back to top Go down
Wayne
Member
Member
Wayne

Posts : 1
Join date : 2011-07-05

"Press any key to continue..." Empty
PostSubject: Re: "Press any key to continue..."   "Press any key to continue..." EmptyThu Jul 14, 2011 12:30 am

Where does one find the "any" key? I do not see this one on my keyboard.
Back to top Go down
Plobo
Member
Member
Plobo

Posts : 3
Join date : 2011-07-11

"Press any key to continue..." Empty
PostSubject: Re: "Press any key to continue..."   "Press any key to continue..." EmptyThu Jul 14, 2011 12:31 am

Wayne wrote:
Where does one find the "any" key? I do not see this one on my keyboard.

it's between the "F" and the "G" keys. You have to pry up the keys to access it.
Back to top Go down
Sponsored content




"Press any key to continue..." Empty
PostSubject: Re: "Press any key to continue..."   "Press any key to continue..." Empty

Back to top Go down
 

"Press any key to continue..."

View previous topic View next topic Back to top 
Page 1 of 1

Permissions in this forum:You cannot reply to topics in this forum
Easy A :: "Press any key to continue..." Edit-trash Useless :: Trash-