Results 1 to 10 of 10

Thread: Get both the Keycode and Ascii values of keys pressed

  1. #1
    Web developer Nightwalker83's Avatar
    Join Date
    Dec 01
    Location
    Adelaide, Australia
    Posts
    9,731

    Get both the Keycode and Ascii values of keys pressed

    Use this app to get the Ascii values of the keys on the keyboard.
    Attached Files Attached Files
    Last edited by Nightwalker83; Apr 29th, 2011 at 03:39 AM. Reason: Reuploading source code!
    If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu.
    Please consider giving me some rep points if I help you a lot.
    DON'T BUMP YOUR POSTS!!! Links to my code examples can now be found on my website: My websites
    Please rate my post if you find it helpful!
    Technology is a dangerous thing in the hands of an idiot! I am that idiot.

  2. #2
    INXSIVE Bruce Fox's Avatar
    Join Date
    Sep 01
    Location
    Melbourne, Australia
    Posts
    7,401
    Didn't try the .exe tho (viruses)

    But this is also an option:
    VB Code:
    1. 'Place a ListBox on a Form.
    2. 'Will display All Ascii Characters
    3. Private Sub Form_Load()
    4. Dim i As Integer
    5.  
    6.     For i = 0 To 255
    7.         List1.AddItem "Decimal: " & i & " = Char: " & Chr(i)
    8.     Next
    9. End Sub
    Handy References:
    MSDN Library
    ADO Tutorial Excel Tutorial MZTools (VB6)

    • Please pull down the Thread Tools menu and click the 'Mark Thread Resolved' button, or alternately edit your original post and add "Resolved" or place a in the subject when your question(s) have been answered.
    • Please use code tags [highlight=vb] your code goes here between the tags [/highlight] when posting code.

  3. #3
    Web developer Nightwalker83's Avatar
    Join Date
    Dec 01
    Location
    Adelaide, Australia
    Posts
    9,731

    Get both the Keycode and Ascii values of keys pressed

    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:
    1. Private Sub Command1_Click()
    2. Unload Me
    3. 'End
    4. End Sub
    5.  
    6. Private Sub Text1_Change()
    7. Open App.Path & "\keyboard.txt" For Append As #1
    8. Print #1, Label2.Caption & " " & Text1.Text
    9. Close #1
    10. End Sub
    11.  
    12. Private Sub Text1_KeyDown(KeyCode As Integer, Shift As Integer)
    13. Label2.Caption = Chr(KeyCode)
    14. Text1.Text = KeyCode
    15. End Sub
    16.  
    17.  
    18. Private Sub Text1_KeyPress(KeyAscii As Integer)
    19. Label2.Caption = Chr(KeyAscii)
    20.  MsgBox "Asciikey: " & KeyAscii
    21. End 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
    Last edited by Nightwalker83; Mar 15th, 2010 at 08:28 PM. Reason: Fixing spelling
    If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu.
    Please consider giving me some rep points if I help you a lot.
    DON'T BUMP YOUR POSTS!!! Links to my code examples can now be found on my website: My websites
    Please rate my post if you find it helpful!
    Technology is a dangerous thing in the hands of an idiot! I am that idiot.

  4. #4
    New Member
    Join Date
    Mar 10
    Posts
    1

    Re: Get both the Keycode and Ascii values of keys pressed

    helpful ty

  5. #5
    Freelancer akhileshbc's Avatar
    Join Date
    Jun 08
    Location
    Trivandrum, Kerala, India
    Posts
    7,557

    Re: Get both the Keycode and Ascii values of keys pressed

    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? ...

    Good luck ...

    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 Athlon X2 5200+, ASUS Motherboard, 2 GB RAM, 400 GB HDD, Nvidia 8600 GT 512MB, 19.5" TFT(Wide), Creative 5.1 Home Theater

    Social Group: VBForums - Developers from India

    Skills: PHP, MySQL, jQuery, VB.Net, VB6, Photoshop...

  6. #6
    Web developer Nightwalker83's Avatar
    Join Date
    Dec 01
    Location
    Adelaide, Australia
    Posts
    9,731

    Re: Get both the Keycode and Ascii values of keys pressed

    Quote Originally Posted by akhileshbc View Post
    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.
    If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu.
    Please consider giving me some rep points if I help you a lot.
    DON'T BUMP YOUR POSTS!!! Links to my code examples can now be found on my website: My websites
    Please rate my post if you find it helpful!
    Technology is a dangerous thing in the hands of an idiot! I am that idiot.

  7. #7
    Freelancer akhileshbc's Avatar
    Join Date
    Jun 08
    Location
    Trivandrum, Kerala, India
    Posts
    7,557

    Re: Get both the Keycode and Ascii values of keys pressed

    Quote Originally Posted by Nightwalker83 View Post
    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...???

    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 Athlon X2 5200+, ASUS Motherboard, 2 GB RAM, 400 GB HDD, Nvidia 8600 GT 512MB, 19.5" TFT(Wide), Creative 5.1 Home Theater

    Social Group: VBForums - Developers from India

    Skills: PHP, MySQL, jQuery, VB.Net, VB6, Photoshop...

  8. #8
    Web developer Nightwalker83's Avatar
    Join Date
    Dec 01
    Location
    Adelaide, Australia
    Posts
    9,731

    Re: Get both the Keycode and Ascii values of keys pressed

    Quote Originally Posted by akhileshbc View Post
    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.
    If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu.
    Please consider giving me some rep points if I help you a lot.
    DON'T BUMP YOUR POSTS!!! Links to my code examples can now be found on my website: My websites
    Please rate my post if you find it helpful!
    Technology is a dangerous thing in the hands of an idiot! I am that idiot.

  9. #9
    Freelancer akhileshbc's Avatar
    Join Date
    Jun 08
    Location
    Trivandrum, Kerala, India
    Posts
    7,557

    Re: Get both the Keycode and Ascii values of keys pressed

    Quote Originally Posted by Nightwalker83 View Post
    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.
    ....
    Quote Originally Posted by Nightwalker83 View Post
    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:
    Code:
    Private Sub Command1_Click()
    Unload Me
    'End
    End Sub
    ( I am just expressing my thoughts )...

    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 Athlon X2 5200+, ASUS Motherboard, 2 GB RAM, 400 GB HDD, Nvidia 8600 GT 512MB, 19.5" TFT(Wide), Creative 5.1 Home Theater

    Social Group: VBForums - Developers from India

    Skills: PHP, MySQL, jQuery, VB.Net, VB6, Photoshop...

  10. #10
    Web developer Nightwalker83's Avatar
    Join Date
    Dec 01
    Location
    Adelaide, Australia
    Posts
    9,731

    Re: Get both the Keycode and Ascii values of keys pressed

    Quote Originally Posted by akhileshbc View Post
    ....


    Then I think, this code block itself is not needed:
    Code:
    Private Sub Command1_Click()
    Unload Me
    'End
    End Sub
    ( I am just expressing my thoughts )...
    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.
    If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu.
    Please consider giving me some rep points if I help you a lot.
    DON'T BUMP YOUR POSTS!!! Links to my code examples can now be found on my website: My websites
    Please rate my post if you find it helpful!
    Technology is a dangerous thing in the hands of an idiot! I am that idiot.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •