# VBForums CodeBank > CodeBank - Visual Basic 6 and earlier >  Get both the Keycode and Ascii values of keys pressed

## Nightwalker83

Use this app to get the Ascii values of the keys on the keyboard.

----------


## Bruce Fox

Didn't try the .exe tho (viruses)  :Smilie: 

But this is also an option:

VB Code:
'Place a ListBox on a Form.
'Will display All Ascii Characters
Private Sub Form_Load()
Dim i As Integer
     For i = 0 To 255
        List1.AddItem "Decimal: " & i & " = Char: " & Chr(i)
    Next
End Sub

----------


## Nightwalker83

Hi,

This code will output (to a text file) the ascii value of the key on the keyboard which was pressed. This code was written in Visual Basic 6.0.


vb Code:
Private Sub Command1_Click()Unload Me'EndEnd Sub Private Sub Text1_Change()Open App.Path & "\keyboard.txt" For Append As #1Print #1, Label2.Caption & " " & Text1.TextClose #1End Sub Private Sub Text1_KeyDown(KeyCode As Integer, Shift As Integer)Label2.Caption = Chr(KeyCode)Text1.Text = KeyCodeEnd Sub  Private Sub Text1_KeyPress(KeyAscii As Integer)Label2.Caption = Chr(KeyAscii) MsgBox "Asciikey: " & KeyAsciiEnd Sub

Edit:

The commented out parts were apart of the original code but are not needed to preform the task suggested in the thread title.

Nightwalker

----------


## Medical Mainiac

:Smilie:  helpful ty

----------


## akhileshbc

I found that you are using *End* in most of your projects. That's not a good practice. See this FAQ for more details: Why is using the 'End' statement (or VB's "stop" button) a bad idea? ... :wave: 

Good luck ...  :Thumb:

----------


## Nightwalker83

> I found that you are using *End* in most of your projects. That's not a good practice.
> 
> Good luck ...


Yeah, I know! However since, it has been years since I originally wrote the code I hadn't double checked to make sure I used unload me instead of end.

----------


## akhileshbc

> Yeah, I know! However since, it has been years since I originally wrote the code I hadn't double checked to make sure I used unload me instead of end.


Why don't you edit your post(the above one) and include it now...???  :Smilie:

----------


## Nightwalker83

> Why don't you edit your post(the above one) and include it now...???


I have amended post #3 and put unload me in Command1_Click but I has left the end in there but commented it out. There is an explanation of why I did this in post #3.

----------


## akhileshbc

> I have amended post #3 and put unload me in Command1_Click but I has left the end in there but commented it out. There is an explanation of why I did this in post #3.


.... :Thumb: 



> Edit:
> 
> The commented out parts were apart of the original code but are not needed to preform the task suggested in the thread title.
> 
> Nightwalker


Then I think, this code block itself is not needed:


```
Private Sub Command1_Click()
Unload Me
'End
End Sub
```

_( I am just expressing my thoughts )_...  :wave:

----------


## Nightwalker83

> ....
> 
> 
> Then I think, this code block itself is not needed:
> 
> 
> ```
> Private Sub Command1_Click()
> Unload Me
> ...


Ah well, the users can decided whether they want to keep it in there or not. Maybe it will come in handy for something else I'm not forcing them to use any of the code.

----------

