943,438 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 3977
  • C++ RSS
Feb 19th, 2005
0

reading key combinations

Expand Post »
hi .. im doin an assignment on edlin text editor..
while implementing the insert new line function i need to exit a loop when a key combination is pressed..
inside the loop there will be some lines reading input from the user..so will be somting like below
while( ? )
{
getline(........
}

for example when user presses "<ctrl> + c" it should exit the loop.
........i cant figure out how to implement this .... some one plz help me .... my assignment is due dayafter. ..thanks
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
samyn is offline Offline
2 posts
since Feb 2005
Feb 19th, 2005
0

Re: reading key combinations

There are many solutions to this problem, but I'm going to assume you are not using curses or terminal libraries.


With gdb, break just after the getline (..) statement as see what the input buffer contains and then formulate your code based on that. For example let's say pressing F3 sends a 3 byte combination (EC 7F 03). Then

C++ Syntax (Toggle Plain Text)
  1. switch (Buffer [0]) {
  2. case 0xEC:
  3. ; Because a function key always has 3 bytes we might assume next is 7F.
  4. if (Buffer [2] == 3) {
  5. ; Do whatever is required base on F3 key
  6. }
  7. }
NOTE: This code doesn't represent actual circumstanses but rather how the key combination could be trapped base on this hypothetical situaltion.
Reputation Points: 47
Solved Threads: 17
Posting Whiz in Training
Tight_Coder_Ex is offline Offline
215 posts
since Feb 2005
Feb 19th, 2005
0

Re: reading key combinations

thanks for ur reply but i didn quite undestand the above...
how do i get the raw input??

im using dev-c++ by the way...
Reputation Points: 10
Solved Threads: 0
Newbie Poster
samyn is offline Offline
2 posts
since Feb 2005

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: fstream and saving to a:\
Next Thread in C++ Forum Timeline: Ze SDL way to do multimedia programming





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC