Jump to content

[PASCAL] Keyboard program


CouldnoT
 Share

Recommended Posts

Keyboard program

 

In this example, we will get a character from keyboard and the application will tell us the row number of the entered key on the keyboard:

 

var
 Key: Char;
begin
 Write('Please enter any English letter: ');
 Readln(Key);
 Writeln;
 case Key of
 'q', 'w', 'e', 'r', 't', 'y', 'u', 'i', 'o', 'p':
 Writeln('This is in the second row in keyboard');
 'a', 's', 'd', 'f', 'g', 'h', 'j', 'k', 'l':
 Writeln('This is in the third row in keyboard');
 'z', 'x', 'c', 'v', 'b', 'n', 'm':
 Writeln('This is in the fourth row in keyboard');
 else
 Writeln('Unknown letter');
 end;
 Write('Press enter key to close');
 Readln;
end. 

 

Note that we have used a new technique in the case condition, which is a set of values:

    'z', 'x', 'c', 'v', 'b', 'n', 'm': 

which means execute case branch statement if the Key was one of these values set: z, x, c, v, b, n or m We can also mix ranges with values set like this:

    'a' .. 'd', 'x', 'y', 'z': 

which means execute the statement if the value falls between a and d, or equal to x, y or z.

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
 Share

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.