C# 0 The Complete Reference


KeyChar  contains the  char



Download 4,07 Mb.
Pdf ko'rish
bet479/1096
Sana23.01.2022
Hajmi4,07 Mb.
#402171
1   ...   475   476   477   478   479   480   481   482   ...   1096
Bog'liq
C-Sharp 3 The Complete Reference Herbert Schildt

KeyChar

 contains the 



char

 equivalent of the character that was pressed. 



Key

 contains a 

value from the 

ConsoleKey

 enumeration, which is an enumeration of all the keys on the 

keyboard. 

Modifiers

 describes which, if any, of the keyboard modifiers 

ATL

,

CTRL



, or 

SHIFT


were pressed when the keystroke was generated. These modifiers are represented by the 

ConsoleModifiers

 enumeration, which has these values: 



Control

,

Shift

, and 

Alt

. More than 

one modifier value might be present in 

Modifiers

.

The major advantage to 



ReadKey( )

 is that it provides a means of achieving interactive 

keyboard input because it is not line buffered. To see the effect of this, try the following 

program:


// Read keystrokes from the console by using ReadKey().

using System;

class ReadKeys {

  static void Main() {

    ConsoleKeyInfo keypress;

    Console.WriteLine("Enter keystrokes. Enter Q to stop.");

    do {

      keypress = Console.ReadKey(); // read keystrokes

      Console.WriteLine(" Your key is: " + keypress.KeyChar);

      // Check for modifier keys.

      if((ConsoleModifiers.Alt & keypress.Modifiers) != 0)

        Console.WriteLine("Alt key pressed.");

      if((ConsoleModifiers.Control & keypress.Modifiers) != 0)

        Console.WriteLine("Control key pressed.");

      if((ConsoleModifiers.Shift & keypress.Modifiers) != 0)

        Console.WriteLine("Shift key pressed.");

    } while(keypress.KeyChar != 'Q');

  }


}

A sample run is shown here:

Enter keystrokes. Enter Q to stop.

a Your key is: a

b Your key is: b

d Your key is: d

A Your key is: A

Shift key pressed.

B Your key is: B

Shift key pressed.

C Your key is: C

Shift key pressed.

• Your key is: •

Control key pressed.

Q Your key is: Q

Shift key pressed.

www.freepdf-books.com



Download 4,07 Mb.

Do'stlaringiz bilan baham:
1   ...   475   476   477   478   479   480   481   482   ...   1096




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©hozir.org 2024
ma'muriyatiga murojaat qiling

kiriting | ro'yxatdan o'tish
    Bosh sahifa
юртда тантана
Боғда битган
Бугун юртда
Эшитганлар жилманглар
Эшитмадим деманглар
битган бодомлар
Yangiariq tumani
qitish marakazi
Raqamli texnologiyalar
ilishida muhokamadan
tasdiqqa tavsiya
tavsiya etilgan
iqtisodiyot kafedrasi
steiermarkischen landesregierung
asarlaringizni yuboring
o'zingizning asarlaringizni
Iltimos faqat
faqat o'zingizning
steierm rkischen
landesregierung fachabteilung
rkischen landesregierung
hamshira loyihasi
loyihasi mavsum
faolyatining oqibatlari
asosiy adabiyotlar
fakulteti ahborot
ahborot havfsizligi
havfsizligi kafedrasi
fanidan bo’yicha
fakulteti iqtisodiyot
boshqaruv fakulteti
chiqarishda boshqaruv
ishlab chiqarishda
iqtisodiyot fakultet
multiservis tarmoqlari
fanidan asosiy
Uzbek fanidan
mavzulari potok
asosidagi multiservis
'aliyyil a'ziym
billahil 'aliyyil
illaa billahil
quvvata illaa
falah' deganida
Kompyuter savodxonligi
bo’yicha mustaqil
'alal falah'
Hayya 'alal
'alas soloh
Hayya 'alas
mavsum boyicha


yuklab olish