2 Replies - 1047 Views - Last Post: 27 December 2013 - 08:00 AM Rate Topic: -----

#1 Canis   User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 58
  • Joined: 01-February 13

Getting which key is pressed?

Posted 27 December 2013 - 04:05 AM

Hello all! I am writing up a program for something and
I want to know if there is a way to check which key is pressed without it showing on the screen,
for example if i press the letter 'k', i want to be able to check it first, and THEN print it or do whatever else.. so something like:
if(keypressed=='k'){
printf("%c",k);
}



I know how to do this in assembly, but i was wondering if there is a way to do this in higher level languages, i'd imagine it has to do something with the system commands?

Anyway, thanks bunch for your help!

Is This A Good Question/Topic? 0
  • +

Replies To: Getting which key is pressed?

#2 tarmizi_adam2005   User is offline

  • جوروترا

Reputation: 287
  • View blog
  • Posts: 986
  • Joined: 18-April 09

Re: Getting which key is pressed?

Posted 27 December 2013 - 05:00 AM

Hi,

I'm not sure about not showing it on the screen. But if you want to hide an entered password with '*' maybe this link could help

http://stackoverflow...tain-characters

http://www.cplusplus...m/general/3570/
Was This Post Helpful? 1
  • +
  • -

#3 Skydiver   User is offline

  • Code herder
  • member icon

Reputation: 7915
  • View blog
  • Posts: 26,425
  • Joined: 05-May 12

Re: Getting which key is pressed?

Posted 27 December 2013 - 08:00 AM

Yup. In general, you have to write platform specific code or use a library that abstracts away the platform specific code. If you were forced to just use the standard C/C++ library, you can't control the echoing of the character that was entered at the console.
Was This Post Helpful? 1
  • +
  • -

Page 1 of 1