1 / 16

Programming In C++

Programming In C++. Spring Semester 2013 Lecture 8. Extended Keyboard Codes. As we know that keyboard usually generates the ASCII codes for letters, numbers and punctuation. Such keys all generate one-byte ASCII codes.

cricket
Download Presentation

Programming In C++

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Programming In C++ Spring Semester 2013 Lecture 8 Programming In C++, Lecture 8 By Umer Rana

  2. Extended Keyboard Codes As we know that keyboard usually generates the ASCII codes for letters, numbers and punctuation. Such keys all generate one-byte ASCII codes. However, there are a great many keys and key combinations not represented by this one-byte character set. For instance, the function keys, F1 to F10, are not represented by a single byte. That keys consists of two bytes; the first byte is 0 and the second byte is a number indicating the particular key(Extended Code). Extended keyboard codes use two characters, the first of which has an ASCII value of 0. Programming In C++, Lecture 8 By Umer Rana

  3. Normal v/s Extended Codes Normal code 1 byte letter ‘a’ 97 0 Extended code 2 bytes function key F1 59 Programming In C++, Lecture 8 By Umer Rana

  4. Normal v/s Extended Codes { unsigned char key, key2; while ( ( key=getch( ) )!= '\r' ) if (key==0) { key2=getch(); printf("%3d %3d\n", key, key2); } else printf("%3d\n", key); getche(); } Programming In C++, Lecture 8 By Umer Rana

  5. Cursor Control with ANSI.SYS Cursor control is achieved with ANSI.SYS using escape sequences (a string of several special characters). Void main (void) { while ( getche ( ) != ‘\r’) // Printer Character printf(“\x1B[B”); // Cursor Down } ALL ANSI.SYS commands begin with the escape sequence, “\x1B[“ Programming In C++, Lecture 8 By Umer Rana

  6. Cursor Control with ANSI.SYS Have many more codes see the Book Page 284 Programming In C++, Lecture 8 By Umer Rana

  7. Cursor Control with Keyboard As we know about extended character codes and cursor control, we can put both ideas together to control the cursor with the arrow keys. #define CLEAR “\x1B[2J” #define C_LEFT “\x1B[D” #define C_RITE “\x1B[C” #define C_UP “\x1B[A” #define C_DOWN “\x1B[B” #define L_ARRO 75 #define R-ARRO 77 #define U-ARRO 72 #define D-ARRO 80 #define ACROSS 205 #define UPDOWN 186 Programming In C++, Lecture 8 By Umer Rana

  8. Cursor Control with Keyboard Void main (void) { Int key; Printf(CLEAR); While ( (key=getch() ) ==0) { Key=getch(); Switch (key) { case L_ARRO: printf(C_LEFT); putch(ACROSS); break; case R_ARRO: printf(C_RITE); putch(ACROSS); break; case U_ARRO: printf(C_UP); putch(UPDOWN); break; case D_ARRO: printf(C_DOWN); putch(UPDOWN); break; } Printf(C_LEFT); } } Programming In C++, Lecture 8 By Umer Rana

  9. Cursor Control with Keyboard putch(): This function is analogous to the getch() function, except that it prints a character on the screen, rather than reading a character from the keyboard. Programming In C++, Lecture 8 By Umer Rana

  10. Moving the Cursor to an Arbitrary Position #define CLEAR “\x1B[2j” #define ERASE“\x1B[K” void main () { int row=1,col=1; while(row !=0) { printf(“\x1B[23;1f”); printf(ERASE); printf(“Type row & column number (from 10,40):”); scanf(“%d,%d”,&row,&col); printf(“\x1B[%d;%df”,row,col); printf(“*(%d,%d)”,row,col); } } Programming In C++, Lecture 8 By Umer Rana

  11. Character Attributes The “Attribute” of a Character describes its apperance: e.g.Print in Bold,Nomal, blinking, UnderLineor in Reverse Every character displayed on the screen is stored in the computer’s memory as two bytes. One byte contains the normal code for the character, while the other bytes contains the character’s attribute. Attribute of Character or String using to set ANSI.sys escape sequence following the bracket, consists of a number, followed by the letter ‘m’. e.g. “\x1B[0m” Programming In C++, Lecture 8 By Umer Rana

  12. Character Attributes 0 Turn off Attribute, “\x1B[0m” Normal White on Black 1 Bold “\x1B[1m” 4 Underline “\x1B[4m” 5 Blinking “\x1B[5m” 7 Reverse “\x1B[7m” 8 Invisible “\x1B[8m” Programming In C++, Lecture 8 By Umer Rana

  13. Command-Line Arguments When we invoke the program from the operating system, we can type not only the name of the program, but various other items as well, such as the name of a file the application is to work on. C>wordprocletter.txt “letter.txt” is used as a command line argument an argument that appears on the command line. Programming In C++, Lecture 8 By Umer Rana

  14. Redirection The MS-DOS operating system incorporates a powerful feature that allows a program to read and write files even when this capability has not been build into the program. This is done through a process called Redirection. Redirection provides an easy way to save the results of a program; its use vaguely similar to that of the [Ctrl][PrtSc] key combination to save program output to the printer, except that the results can be sent to a disk file. Similarly, Redirection can be used to read information from a disk file directly into a program. Output can be Redirected to go to a file instead of the screen; input can be Redirected to come from a file instead of the keyboard. Programming In C++, Lecture 8 By Umer Rana

  15. Redirection Redirection Output The Redirection output operator which is the greater than symbol(>), causes any output intended for the screen to be written to the file whose name follows the operator. C:> programName>file.txt The data to be redirected to a file does not need to be typed by user, the program itself can generate it. Any output normally send to the screen can be redirected to a disk file. Programming In C++, Lecture 8 By Umer Rana

  16. Redirection Redirection Input The Redirection input operator which is the Less than symbol(<), causes redirect the input to a program so, instead of reading characters from the keyboard the program reads them from the file. C:> programName<file.txt Programming In C++, Lecture 8 By Umer Rana

More Related