200 likes | 352 Views
Keyboards, Pages & Transforms. By Yi-Yang Huang & Jayashree Venkatesh. Ignoring the keyboard. Microsoft windows and windows forms class handle many keyboard functions themselves. Ignore keystrokes in menu selection.
E N D
Keyboards, Pages & Transforms By Yi-Yang Huang & Jayashree Venkatesh
Ignoring the keyboard • Microsoft windows and windows forms class handle many keyboard functions themselves. • Ignore keystrokes in menu selection. • Windows forms programs define keyboard accelerators to invoke common menu items. • Dialog boxes also have a keyboard interface, but programs need not monitor the keyboard when a dialog box is active.
Who’s got the focus? • A particular keystroke has only a single destination, which is of type Control or a descendant of Control, such as Form. • Active form is usually the topmost form on the desktop. • Active form is available from the only static property implemented by Form. • Type : Form Property : ActiveForm Accessibility : get
Form Methods (selection) void Activate() • Form Events (selection) Event Method Delegate Argument --------------------------------------------------------------- Activated OnActivated EventHandler EventArgs Deactivate OnDeactivate EventHandler EventArgs
Keyboards and Characters • Keyboard can be • A collection of distinct physical keys • A means of generating character codes (Unicode). • Four groups of keys • Toggle keys (Caps, Num, Scroll locks, Insert) • Shift keys (Shift, Ctrl, Alt) • Noncharacter keys (function, pause, del) • Character keys (letter,no,Tab,Backspace,Enter,Esc)
Keys Down and Keys Up • Control Events (selection) Event Method Delegate Argument --------------------------------------------------------------- KeyDown OnKeyDown KeyEventHandler KeyEventArgs KeyUp OnKeyUp KeyEventHandler KeyEventArgs protected override void OnKeyDown (KeyEventArgs kea) { … }
protected override void OnKeyUp (KeyEventArgs kea) { … } Void MyKeyDownHandler (object objSender, KeyEventsArgs kea) { … } Void MyKeyUpHandler (object objSender, KeyEventsArgs kea) { … }
cntl.KeyDown += new KeyEventHandler (MyKeyDownHandler); cntl.KeyUp += new KeyEventHandler (MyKeyUpHandler); KeyEventArgs Properties Type Property Accessibility ------------------------------------------ Keys KeyCode get Keys Modifiers get Keys KeyData get Bool Shift get Bool Control get Bool Alt get Bool Handled get/set Int KeyValue get
Keys Enumeration • Keys has 26 members Keys Enumeration (letters) A – 65 , B – 66 , ….., Z – 90 Keys Enumeration(numbers) D0 – 48, D1 – 49 ….D9 -- 57 Keys Enumeration (function keys) F1 – 112, F2 – 113….F24 – 135.
Keys Enumeration (keypad operators) Multiply – 106, Add – 107, Subtract – 109, Divide – 111 Also of Keys Enumeration are the foll: • Keypad unused - Separator • Keypad cursor movement – Home, Left, End, Insert, Up, Clear, Down, Right, Pageup / Pagedown, Right, Delete • ASCII control keys – Back, Tab, Linefeed, Enter Return, Escape, Space • Shift keys – Shift, Control , Menu, LShiftkey, Lcontrolkey, LMenu, RShiftkey, RControlkey,RMenu
Microsoft keys – LWin, RWin, Apps • Miscellaneous – Cancel, Pause, Capslock, Printscreen, Numlock, Scroll • Mouse buttons – LButton, RButton, MButton • Special keys – Select, Print, Execute, Help, Processkey, Attn, Play, Zoom • Symbols – Oemsemicolon, Oemplus, Oemcomma, Oemminus, Oemperiod, OemQuestion, Oemtilde, OemPipe, Oemquotes, Oembackslash
Browsers and players – browserback, browserforward, browserrefresh, browserstop,…., volumemute, volumedown, volumeup,..,launchapplication1,…,mediastop,… • IME (Input method editor) – Finalmode, Kanjamode, IMEconvert,IMEaccept…. • Modifier keys – none,shift,control, alt • Eg: Shift followed by D • Masks are provided for differentiating the keycodes and modifiers.
Testing the modifier keys • State of modifier keys can also be obtained using the static Control.ModifierKeys property. Keys keysmod =Control.ModifierKeys If (keysMod == (Keys.Shift | Keys.Control)) { // Shift and Ctrl and pressed } If (keysMod == Keys.Shift) { // Shift is pressed } If (keysMod == Keys.Control)) { // Ctrl is pressed }
Reality check • Problems with Capslock • KeyDown is mostly used for cursor movement, Insert and Delete KeyPress for Characters Control Events(selection) Event Method Delegate Argument ----------------------------------------------------------------------------------------------------- KeyPress OnKeyPress KeyPressEventHandler KeyPressEventArgs
KeyPressEventArgs Properties Type Property Accessibility ------------------------------------------ char KeyChar get bool Handled get/set Control Characters Keyboard-Generated Control Characters Key Control Character --------------------------------------------- Shift + Ctrl @ 0x0000 Backspace 0x0008 …….
Invoking the Win32 API • Platform Invocation Services ScrollWindow: Bool Scrollwindow(HWND hwnd, int Xamount, int Yamount, const RECT * lprect.CONST RECT * lpclipRECT); Typedef struct tagRECT { Long left; Long top; Long right; Long bottom; }RECT;
Handling input from foreign keyboards Control panel – regional options – general tab – change the language settings – reboot • Input focus Determines which control gets keyboard input. Control Properties (selection) Type Property Accessibility --------------------------------------------- bool CanFocus get bool ContainsFocus get Bool Focused get
Control Methods (selection) Bool Focus ( ) Control Events(selection) Event Method Delegate Argument ----------------------------------------------------------------------------------- GotFocus OnGotFocus EventHandler EventArgs The Missing Caret Cursor is instead referred in Windows as a caret. Caret caret = new Caret (form);
Caret Properties Type Property Accessibility ----------------------------------------------- Control Control get Size Size get/set Point Position get/set Bool Visibility get/set size of Caret : Caret.Size = new Size( 2, Font.height); Caret Methods : Void Hide(); Void Show(); Void Dispose();
protected override void OnGotFocus (EventArgs ea) { Base.OnGotFocus(ea); … } protected override void OnLostFocus (EventArgs ea) { Base.OnLostFocus(ea); … }