📄 consolekeyinfo.cls
字号:
VERSION 1.0 CLASS
BEGIN
MultiUse = -1 'True
Persistable = 1 'Persistable
DataBindingBehavior = 0 'vbNone
DataSourceBehavior = 0 'vbNone
MTSTransactionMode = 0 'NotAnMTSObject
END
Attribute VB_Name = "ConsoleKeyInfo"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = True
' CopyRight (c) 2005 Kelly Ethridge
'
' This file is part of VBCorLib.
'
' VBCorLib is free software; you can redistribute it and/or modify
' it under the terms of the GNU Library General Public License as published by
' the Free Software Foundation; either version 2.1 of the License, or
' (at your option) any later version.
'
' VBCorLib is distributed in the hope that it will be useful,
' but WITHOUT ANY WARRANTY; without even the implied warranty of
' MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
' GNU Library General Public License for more details.
'
' You should have received a copy of the GNU Library General Public License
' along with Foobar; if not, write to the Free Software
' Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
'
' Module: ConsoleKeyInfo
'
''
' Represents the information contained in a console key press.
'
' @remarks When a key pressed on a console, a <b>ConsoleKeyInfo</b>
' object is generated by reading the pressed key using the <b>ReadKey</b>
' method. The generated object contains the key press information
' describing the event.
'
' @see Console
'
Option Explicit
Implements IObject
''
' A list of all the scankey codes.
'
' @param AKey The A key.
' @param AddKey The keypad plus key.
' @param ApplicationsKey The application key (Microsoft Natual Keyboard)
' @param AttentionKey The ATTN key.
' @param BKey The B key.
' @param BackSpaceKey The BackSpace key.
' @param BrowserBackKey The Browser Back key (Windows 2000 or later)
' @param BrowserFavoritesKey The Browser Favorites key (Windows 2000 or later)
' @param BrowserForwardKey The Browser Forward key (Windows 2000 or later)
' @param BrowserHomeKey The Browser Home key (Windows 2000 or later)
' @param BrowserRefreshKey The Browser Refresh key (Windows 2000 or later)
' @param BrowserSearchKey The Browser Search key (Windows 2000 or later)
' @param BrowserStopKey The Browser Stop key (Windows 2000 or later)
' @param CKey The C Key.
' @param ClearKey The CLEAR key.
' @param CrSelKey The CRSEL (CURSOR SELECT) key.
' @param DKey The D key.
' @param D0Key The 0 key.
' @param D1Key The 1 key.
' @param D2Key The 2 key.
' @param D3Key The 3 key.
' @param D4Key The 4 key.
' @param D5Key The 5 key.
' @param D6Key The 6 key.
' @param D7Key The 7 key.
' @param D8Key The 8 Key.
' @param D9Key The 9 key.
' @param DecimalKey The Decimal key.
' @param DeleteKey The Delete key.
' @param DivideKey The divide key.
' @param DownArrowKey The DOWN ARROW key.
' @param EKey The E key.
' @param EndKey The END key.
' @param EnterKey The Enter key.
' @param EraseEndOfFileKey The ERASE EOF key.
' @param EscapeKey The ESC (ESCAPE) key.
' @param ExecuteKey The EXECUTE key.
' @param ExSelKey The EXSEL (EXTEND SELECTION) key.
' @param FKey The F key.
' @param F1Key The F1 key.
' @param F2Key The F2 key.
' @param F3Key The F3 key.
' @param F4Key The F4 key.
' @param F5Key The F5 key.
' @param F6Key The F6 key.
' @param F7Key The F7 key.
' @param F8Key The F8 key.
' @param F9Key The F9 key.
' @param F10Key The F10 key.
' @param F11Key The F11 key.
' @param F12Key The F12 key.
' @param F13Key The F13 key.
' @param F14Key The F14 key.
' @param F15Key The F15 key.
' @param F16Key The F16 key.
' @param F17Key The F17 key.
' @param F18Key The F18 key.
' @param F19Key The F19 key.
' @param F20Key The F20 key.
' @param F21Key The F21 key.
' @param F22Key The F22 key.
' @param F23Key The F23 key.
' @param F24Key The F24 key.
' @param GKey The G key.
' @param HKey The H key.
' @param HelpKey The HELP key.
' @param HomeKey The HOME key.
' @param IKey The I key.
' @param InsertKey The INS (INSERT) key.
' @param JKey The J key.
' @param KKey The K key.
' @param LKey The L key.
' @param LaunchApp1Key The Start Application 1 key (MS Natural keyboard, Windows 2000 or later)
' @param LaunchApp2Key The Start Application 2 key (MS Natural keyboard, Windows 2000 or later)
' @param LaunchMailKey The Start Mail key (MS Natural keyboard, Windows 2000 or later)
' @param LaunchMediaSelectKey The Select Media key (MS Natural keyboard, Windows 2000 or later)
' @param LeftArrowKey The LEFT ARROW key.
' @param LeftWindowsKey The left Windows logo key.
' @param MKey The M key.
' @param MediaNextKey The Media Next Track key (MS Natural keyboard, Windows 2000 or later)
' @param MediaPlayKey The Media Play Track key (MS Natural keyboard, Windows 2000 or later)
' @param MediaPreviousKey The Media Previous Track key (MS Natural keyboard, Windows 2000 or later)
' @param MediaStopKey The Media Stop key (MS Natural keyboard, Windows 2000 or later)
' @param MultiplyKey The Multiply key.
' @param NKey The N key.
' @param NoNameKey A constant reserved for future use.
' @param NumPad0Key The 0 key on the numeric keypad.
' @param NumPad1Key The 1 key on the numeric keypad.
' @param NumPad2Key The 2 key on the numeric keypad.
' @param NumPad3Key The 3 key on the numeric keypad.
' @param NumPad4Key The 4 key on the numeric keypad.
' @param NumPad5Key The 5 key on the numeric keypad.
' @param NumPad6Key The 6 key on the numeric keypad.
' @param NumPad7Key The 7 key on the numeric keypad.
' @param NumPad8Key The 8 key on the numeric keypad.
' @param NumPad9Key The 9 key on the numeric keypad.
' @param OKey The O key.
' @param Oem1Key The OEM 1 key (OEM Specific)
' @param Oem102Key The OEM 102 key (OEM Specific)
' @param Oem2Key The OEM 2 key (OEM Specific)
' @param Oem3Key The OEM 3 key (OEM Specific)
' @param Oem4Key The OEM 4 key (OEM Specific)
' @param Oem5Key The OEM 5 key (OEM Specific)
' @param Oem6Key The OEM 6 key (OEM Specific)
' @param Oem7Key The OEM 7 key (OEM Specific)
' @param Oem8Key The OEM 8 key (OEM Specific)
' @param OemClearKey The CLEAR key (OEM Specific)
' @param OemCommaKey The Comma Key.
' @param OemMinusKey The Minus key.
' @param OemPeriodKey The Period key.
' @param OemPlusKey The Plus key.
' @param PKey The P key.
' @param Pa1Key The PA1 key.
' @param PacketKey The Packet key (used to pass unicode characters with keystrokes)
' @param PageDownKey The PAGE DOWN key.
' @param PageUpKey The PAGE UP key.
' @param PauseKey The PAUSE key.
' @param PlayKey The PLAY key.
' @param PrintKey The PRINT key.
' @param PrintScreenKey The PRINT SCREEN key.
' @param ProcessKey The IME PROCESS key.
' @param QKey The Q key.
' @param RKey The R Key.
' @param RightArrowKey The RIGHT ARROW key.
' @param RightWindowsKey The right Windows logo key.
' @param SKey The S key.
' @param SelectKey The SELECT key.
' @param SeparatorKey The Separator key.
' @param SleepKey The Computer Sleep key.
' @param SpaceBarKey The Space Bar key.
' @param SubtractKey The Subtract key.
' @param TKey The T key.
' @param TabKey The TAB key.
' @param UKey The U key.
' @param UpArrowKey The UP ARROW key.
' @param VKey The V key.
' @param VolumeDownKey The Volume Down key.
' @param VolumeMuteKey The Volume Mute key.
' @param VolumeUpKey The Volume Up key.
' @param WKey The W key.
' @param XKey The X key.
' @param YKey The Y key.
' @param ZKey The Z key.
' @param ZoomKey The ZOOM key.
'
Public Enum ConsoleKey
AKey = 65
AddKey = 107
ApplicationsKey = 91
AttentionKey = 246
BKey = 66
BackSpaceKey = 8
BrowserBackKey = 166
BrowserFavoritesKey = 171
BrowserForwardKey = 167
BrowserHomeKey = 172
BrowserRefreshKey = 168
BrowserSearchKey = 170
BrowserStopKey = 169
CKey = 67
ClearKey = 12
CrSelKey = 247
DKey = 68
D0Key = 48
D1Key = 49
D2Key = 50
D3Key = 51
D4Key = 52
D5Key = 53
D6Key = 54
D7Key = 55
D8Key = 56
D9Key = 57
DecimalKey = 110
DeleteKey = 46
DivideKey = 111
DownArrowKey = 40
EKey = 69
EndKey = 35
EnterKey = 13
EraseEndOfFileKey = 249
EscapeKey = 27
ExecuteKey = 43
ExSelKey = 248
FKey = 70
F1Key = 112
F2Key = 113
F3Key = 114
F4Key = 115
F5Key = 116
F6Key = 117
F7Key = 118
F8Key = 119
F9Key = 120
F10Key = 121
F11Key = 122
F12Key = 123
F13Key = 124
F14Key = 125
F15Key = 126
F16Key = 127
F17Key = 128
F18Key = 129
F19Key = 130
F20Key = 131
F21Key = 132
F22Key = 133
F23Key = 134
F24Key = 135
GKey = 71
hKey = 72
HelpKey = 47
HomeKey = 36
IKey = 73
InsertKey = 45
JKey = 74
KKey = 75
LKey = 76
LaunchApp1Key = 182
LaunchApp2Key = 183
LaunchMailKey = 180
LaunchMediaSelectKey = 181
LeftArrowKey = 37
LeftWindowsKey = 91
mKey = 77
MediaNextKey = 176
MediaPlayKey = 179
MediaPreviousKey = 177
MediaStopKey = 178
MultiplyKey = 106
NKey = 78
NoNameKey = 252
NumPad0Key = 96
NumPad1Key = 97
NumPad2Key = 98
NumPad3Key = 99
NumPad4Key = 100
NumPad5Key = 101
NumPad6Key = 102
NumPad7Key = 103
NumPad8Key = 104
NumPad9Key = 105
OKey = 79
Oem1Key = 186
Oem102Key = 226
Oem2Key = 191
Oem3Key = 192
Oem4Key = 219
Oem5Key = 220
Oem6Key = 221
Oem7Key = 222
Oem8Key = 223
OemClearKey = 254
OemCommaKey = 188
OemMinusKey = 189
OemPeriodKey = 190
OemPlusKey = 187
PKey = 80
Pa1Key = 253
PacketKey = 231
PageDownKey = 34
PageUpKey = 33
PauseKey = 19
PlayKey = 250
PrintKey = 42
PrintScreenKey = 44
ProcessKey = 229
QKey = 81
RKey = 82
RightArrowKey = 39
RightWindowsKey = 92
SKey = 83
SelectKey = 41
SeparatorKey = 108
SleepKey = 95
SpaceBarKey = 32
SubtractKey = 109
TKey = 84
TabKey = 9
UKey = 85
UpArrowKey = 38
VKey = 86
VolumeDownKey = 174
VolumeMuteKey = 173
VolumeUpKey = 175
WKey = 87
XKey = 88
YKey = 89
ZKey = 90
ZoomKey = 251
End Enum
''
' Values that represent the specific modifier keys
' used to indicate different values for specific keys.
'
' @param AltKey The left or right alt key is specified.
' @param ShiftKey The left or right shift key is specified.
' @param ControlKey The left or right control key is specified.
' @remarks A single key can have different meanings when
' used in combination with these modifiers.
'
Public Enum ConsoleModifiers
AltKey = 1
ShiftKey = 2
ControlKey = 4
End Enum
Private mConsoleKey As ConsoleKey
Private mChar As Integer
Private mModifiers As ConsoleModifiers
''
' Returns the scankey code of the pressed key.
'
' @return Scankey code.
' @remarks This is not the same code as an ascii code.
'
Public Property Get Key() As ConsoleKey
Key = mConsoleKey
End Property
''
' Returns the ascii code of the pressed key.
'
' @return The ascii code.
'
Public Property Get KeyChar() As Integer
KeyChar = mChar
End Property
''
' Returns the state of the key modifiers (Shift, Alt, Control) at
' the time of the key press.
'
' @return Modifier keys state.
'
Public Property Get Modifiers() As ConsoleModifiers
Modifiers = mModifiers
End Property
''
' Returns a string representation of this object instance.
'
' @return String representing this instance.
Public Function ToString() As String
ToString = Object.ToString(Me, App)
End Function
''
' Returns a boolean indicating if the value and this object
' instance are the same instance.
'
' @param value The value to compare equalit to.
' @return Boolean indicating equality.
Public Function Equals(ByRef Value As Variant) As Boolean
If IsObject(Value) Then
If TypeOf Value Is ConsoleKeyInfo Then
Dim Info As ConsoleKeyInfo
Set Info = Value
If Info.GetHashCode <> GetHashCode Then Exit Function
If Info.Key <> mConsoleKey Then Exit Function
If Info.KeyChar <> mChar Then Exit Function
Equals = (Info.Modifiers = mModifiers)
End If
End If
End Function
''
' Returns a pseudo-unique number identifying this instance.
'
' @return Pseudo-unique number identifying this instance.
Public Function GetHashCode() As Long
AsWord(GetHashCode) = mChar
GetHashCode = GetHashCode Or (mModifiers * &H10000)
End Function
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Friend Interface
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Friend Sub Init(ByVal KeyChar As Integer, ByVal Key As ConsoleKey, ByVal Shift As Boolean, ByVal Alt As Boolean, ByVal Control As Boolean)
mChar = KeyChar
mConsoleKey = Key
If Shift Then mModifiers = ShiftKey
If Alt Then mModifiers = mModifiers Or AltKey
If Control Then mModifiers = mModifiers Or ControlKey
End Sub
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Class Events
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Private Sub Class_ReadProperties(PropBag As PropertyBag)
With PropBag
mConsoleKey = .ReadProperty("Key")
mChar = .ReadProperty("Char")
mModifiers = .ReadProperty("Modifier")
End With
End Sub
Private Sub Class_WriteProperties(PropBag As PropertyBag)
With PropBag
Call .WriteProperty("Key", mConsoleKey)
Call .WriteProperty("Char", mChar)
Call .WriteProperty("Modifier", mModifiers)
End With
End Sub
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' IObject Interface
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Private Function IObject_Equals(Value As Variant) As Boolean
IObject_Equals = Equals(Value)
End Function
Private Function IObject_GetHashcode() As Long
IObject_GetHashcode = GetHashCode
End Function
Private Function IObject_ToString() As String
IObject_ToString = ToString
End Function
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -