[Collection] Keyboard Testing Winform (C #)

xiaoxiao2021-03-06  61

using System; using System.Drawing; using System.Windows.Forms; public class KeyExamine: Form {public static void Main () {Application.Run (new KeyExamine ());} enum EventType {None, KeyDown, KeyUp, KeyPress} struct KeyEvent {public EventType evttype; public EventArgs evtargs;} const int iNumLines = 25; int iNumValid = 0; int iInsertIndex = 0; KeyEvent [] akeyevt = new KeyEvent [iNumLines]; int xEvent, xChar, xCode, xMods, xData, xShift, xCtrl, xAlt, xRight; public KeyExamine () {Text = "Key Examine"; BackColor = SystemColors.Window; ForeColor = SystemColors.WindowText; xEvent = 0; xChar = xEvent 5 * Font.Height; xCode = xChar 5 * font.height; xmods = xcode 8 * font.height; xdata = xmods 8 * font.height; xshift = xdata 5 * font.height; xctrl = xshift 5 * font.Height; Xalt = xctrl 5 * font.height; xright = Xalt 5 * font.height; clientsize = new size (xright, font.height * (inumlines 1)); formborderstyle = formborderstyle.fixed3d; maximizebox = f alse;} protected override void OnKeyDown (KeyEventArgs kea) {akeyevt [iInsertIndex] .evttype = EventType.KeyDown; akeyevt [iInsertIndex] .evtargs = kea; onKey ();} protected override void OnKeyUp (KeyEventArgs kea) {akeyevt [iInsertIndex] .evttype = EventType.KeyUp; akeyevt [iInsertIndex] .evtargs = kea; onKey ();} protected override void OnKeyPress (KeyPressEventArgs kpea) {akeyevt [iInsertIndex] .evttype = EventType.KeyPress; akeyevt [iInsertIndex] .evtargs = kpea; ONKEY ();} void onkey () {if (inumvalid

DisplayKeyInfo (grfx, iInsertIndex, iInsertIndex); grfx.Dispose ();} else {ScrollLines ();} iInsertIndex = (iInsertIndex 1)% iNumLines; iNumValid = Math.Min (iNumValid 1, iNumLines);} protected virtual void scrollLines () {Rectangle rect = new Rectangle (0, FontHeight, ClientSize.Width, ClientSize.Height - Font.Height); Invalidate (rect);} protected override void OnPaint (PaintEventArgs pea) {Graphics grfx = pea.Graphics; BoldUnderLine (GRFX, "Event", Xevent, 0); Boldunderline (GRFX, "Keychar", XChar, 0); Boldunderline (GRFX, "Keycode", Xcode, 0); Boldunderline (GRFX, "Modifiers", XMODS, 0) Boldunderline (GRFX, "KeyData", XData, 0); Boldunderline (GRFX, "Shift", Xshift, 0); Boldunderline (GRFX, "Control", XCtrl, 0); Boldunderline (GRFX, "Alt", XALT, 0);

转载请注明原文地址:https://www.9cbs.com/read-84404.html

New Post(0)