|
-
Jul 8th, 2010, 07:13 PM
#1
Thread Starter
Fanatic Member
Is there a way to have a label to show the name for the key that is pressed?
Like, lets say that the keycode is 13. Well, since that is the Enter key, is there something that can convert that 13 to say Enter in the labels caption?
-
Jul 8th, 2010, 08:00 PM
#2
Re: Is there a way to have a label to show the name for the key that is pressed?
Sure, a Select Case or If/Then structure.
Software I use and highly recommend: Opera, Miranda IM, Peerblock, Winamp, Unlocker Assistant, JoyToKey, Virtual CloneDrive, Secunia PSI, ExplorerXP, GOM Player, Real Alternative, Quicktime Alternative,Sumatra PDF, and non-freeware: Photoshop and VB6( ).
My codebank: AllRGB, Rounded Rectangle(math), Binary Server, Buddy Paint, LoadPictureGDI+, System GUID/Volume Serial, HexToAsc, List all processes and their paths, quasiString matching
Strings(search, extraction, retrieval etc): Retrieve BBCode Link from HTML, RemoveBetween ()'s, strFindBetween(str1,str2), Insert text in HTML, HTML - GetSpanByID
-
Jul 8th, 2010, 08:04 PM
#3
Thread Starter
Fanatic Member
Re: Is there a way to have a label to show the name for the key that is pressed?
I was afraid of that.... So there isn't another way?
-
Jul 9th, 2010, 03:11 AM
#4
Re: Is there a way to have a label to show the name for the key that is pressed?
This will get you started:
Code:
Option Explicit
Private Sub Form_KeyUp(KeyCode As Integer, Shift As Integer)
Select Case KeyCode
Case 13: Label1.Caption = "Enter key"
Case 8: Label1.Caption = "Backspace"
Case 27: Label1.Caption = "Escape"
Case 32: Label1.Caption = "Space bar"
Case 46: Label1.Caption = "Delete"
Case 65 To 90, 97 To 122: Label1.Caption = UCase$(Chr$(KeyCode)) '~~~ A to Z
Case 48 To 57: Label1.Caption = CStr(KeyCode - 48) '~~~ 0 to 9
Case Else: Label1.Caption = "Write the code for this !!! ;-)"
End Select
End Sub
Private Sub Form_Load()
Me.KeyPreview = True
End Sub
Add a labelbox to your form and run the code...
If my post was helpful to you, then express your gratitude using Rate this Post. 
And if your problem is SOLVED, then please Mark the Thread as RESOLVED (see it in action - video)
My system: AMD FX 6100, Gigabyte Motherboard, 8 GB Crossair Vengance, Cooler Master 450W Thunder PSU, 1.4 TB HDD, 18.5" TFT(Wide), Antec V1 Cabinet
Social Group: VBForums - Developers from India
Skills: PHP, MySQL, jQuery, VB.Net, Photoshop, CodeIgniter, Bootstrap,...
-
Jul 9th, 2010, 04:16 AM
#5
Re: Is there a way to have a label to show the name for the key that is pressed?
"Enter" is a very generalized term. It is actually called a "Carriage Return"
Please see the link in my signature for Ascii Table. That should help...
A good exercise for the Heart is to bend down and help another up...
Please Mark your Thread " Resolved", if the query is solved
MyGear:
★ CPU ★ Ryzen 5 5800X
★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
★ Keyboard ★ TVS Electronics Gold Keyboard
★ Mouse ★ Logitech G502 Hero
-
Jul 9th, 2010, 04:31 AM
#6
Re: Is there a way to have a label to show the name for the key that is pressed?
 Originally Posted by akhileshbc
This will get you started:
Code:
Option Explicit
Private Sub Form_KeyUp(KeyCode As Integer, Shift As Integer)
Select Case KeyCode
Case 13: Label1.Caption = "Enter key"
Case 8: Label1.Caption = "Backspace"
Case 27: Label1.Caption = "Escape"
Case 32: Label1.Caption = "Space bar"
Case 46: Label1.Caption = "Delete"
Case 65 To 90, 97 To 122: Label1.Caption = UCase$(Chr$(KeyCode)) '~~~ A to Z
Case 48 To 57: Label1.Caption = CStr(KeyCode - 48) '~~~ 0 to 9
Case Else: Label1.Caption = "Write the code for this !!! ;-)"
End Select
End Sub
Private Sub Form_Load()
Me.KeyPreview = True
End Sub
Add a labelbox to your form and run the code... 
akhileshbc made me curious...His post is better for letters but with the magic of cut, paste and Excel here are some more:
Code:
Case 1: Label1.Caption = "Left mouse button"
Case 2: Label1.Caption = "Right mouse button"
Case 3: Label1.Caption = "CANCEL key"
Case 4: Label1.Caption = "Middle mouse button"
Case 8: Label1.Caption = "BACKSPACE key"
Case 9: Label1.Caption = "TAB key"
Case 12: Label1.Caption = "CLEAR key"
Case 13: Label1.Caption = "ENTER key"
Case 16: Label1.Caption = "SHIFT key"
Case 17: Label1.Caption = "CTRL key"
Case 18: Label1.Caption = "MENU key"
Case 19: Label1.Caption = "PAUSE key"
Case 20: Label1.Caption = "CAPS LOCK key"
Case 27: Label1.Caption = "ESC key"
Case 32: Label1.Caption = "SPACEBAR key"
Case 33: Label1.Caption = "PAGE UP key"
Case 34: Label1.Caption = "PAGE DOWN key"
Case 35: Label1.Caption = "END key"
Case 36: Label1.Caption = "HOME key"
Case 37: Label1.Caption = "LEFT ARROW key"
Case 38: Label1.Caption = "UP ARROW key"
Case 39: Label1.Caption = "RIGHT ARROW key"
Case 40: Label1.Caption = "DOWN ARROW key"
Case 41: Label1.Caption = "SELECT key"
Case 42: Label1.Caption = "PRINT SCREEN key"
Case 43: Label1.Caption = "EXECUTE key"
Case 44: Label1.Caption = "SNAPSHOT key"
Case 45: Label1.Caption = "INS key"
Case 46: Label1.Caption = "DEL key"
Case 47: Label1.Caption = "HELP key"
Case 102: Label1.Caption = "6 key"
Case 103: Label1.Caption = "7 key"
Case 104: Label1.Caption = "8 key"
Case 105: Label1.Caption = "9 key"
Case 106: Label1.Caption = "MULTIPLICATION SIGN (*) key"
Case 107: Label1.Caption = "PLUS SIGN (+) key"
Case 108: Label1.Caption = "ENTER (keypad) key"
Case 109: Label1.Caption = "MINUS SIGN (-) key"
Case 110: Label1.Caption = "DECIMAL POINT(.) key"
Case 111: Label1.Caption = "DIVISION SIGN (/) key"
Case 112: Label1.Caption = "F1 key"
Case 113: Label1.Caption = "F2 key"
Case 144: Label1.Caption = "NUM LOCK key"
Case 65: Label1.Caption = "A key"
Case 66: Label1.Caption = "B key"
Case 67: Label1.Caption = "C key"
Case 68: Label1.Caption = "D key"
Case 69: Label1.Caption = "E key"
Case 70: Label1.Caption = "F key"
Case 71: Label1.Caption = "G key"
Case 72: Label1.Caption = "H key"
Case 73: Label1.Caption = "I key"
Case 74: Label1.Caption = "J key"
Case 75: Label1.Caption = "K key"
Case 76: Label1.Caption = "L key"
Case 77: Label1.Caption = "M key"
Case 78: Label1.Caption = "N key"
Case 79: Label1.Caption = "O key"
Case 80: Label1.Caption = "P key"
Case 81: Label1.Caption = "Q key"
Case 82: Label1.Caption = "R key"
Case 83: Label1.Caption = "S key"
Case 84: Label1.Caption = "T key"
Case 85: Label1.Caption = "U key"
Case 86: Label1.Caption = "V key"
Case 87: Label1.Caption = "W key"
Case 88: Label1.Caption = "X key"
Case 89: Label1.Caption = "Y key"
Case 89: Label1.Caption = "z key"
Case 96: Label1.Caption = "0 key"
Case 97: Label1.Caption = "1 key"
Case 98: Label1.Caption = "2 key"
Case 99: Label1.Caption = "3 key"
Case 100: Label1.Caption = "4 key"
Case 101: Label1.Caption = "5 key"
Case 114: Label1.Caption = "F3 key"
Case 115: Label1.Caption = "F4 key"
Case 116: Label1.Caption = "F5 key"
Case 117: Label1.Caption = "F6 key"
Case 118: Label1.Caption = "F7 key"
Case 119: Label1.Caption = "F8 key"
Case 120: Label1.Caption = "F9 key"
Case 121: Label1.Caption = "F10 key"
Case 122: Label1.Caption = "F11 key"
Case 123: Label1.Caption = "F12 key"
Case 124: Label1.Caption = "F13 key"
Case 125: Label1.Caption = "F14 key"
Case 126: Label1.Caption = "F15 key"
Case 127: Label1.Caption = "F16 key"
-
Jul 9th, 2010, 05:17 AM
#7
Re: Is there a way to have a label to show the name for the key that is pressed?
There is API that does this:
Convert a Character Code to a string describing the Keyboard Keys which must be pressed
http://www.vbaccelerator.com/home/vb...ng/article.asp
Add this code to demo:
Private Sub txtChar_KeyPress(KeyAscii As Integer)
Dim vKey As Long
Dim iShift As Long
Debug.Print GetKeyboardString(Chr(KeyAscii), vKey, iShift)
End Sub
-
Jul 9th, 2010, 12:45 PM
#8
Thread Starter
Fanatic Member
Re: Is there a way to have a label to show the name for the key that is pressed?
Well, i was wanting to use the label as an example. But, actually, it is a combobox. If you look in my sig, it is for updating my GetAscynKeyState Button Configuration. I think i already got it though. However, i am going to look at that code DrUnicode posted. Thanks!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|