in

Paul McFedries' Tech Tonic

Making the world a better place, one computer book at a time

Question about ABG-VBA

Last post 02-21-2010 9:21 PM by Golfgazoo. 4 replies.
Page 1 of 1 (5 items)
Sort Posts: Previous Next
  • 02-06-2010 8:22 PM

    • Golfgazoo
    • Top 25 Contributor
    • Joined on 02-06-2010
    • Santa Cruz
    • Posts 3

    Question about ABG-VBA

    I'm learning VBA for Excel (v.2000), and I want to know if there is a function or statement to read the keyboard; not as an input statement, but as a keyboard strobe to detect when a key is hit. Of course, it would be helpful if it returned the value of the key hit as well.

  • 02-09-2010 10:18 AM In reply to

    • Paul
    • Top 10 Contributor
    • Joined on 09-19-2007
    • Toronto
    • Posts 288

    Re: Question about ABG-VBA

    Hi,

    I'm not sure what you're looking to do, but the closest thing that Excel offers is the OnKey method, which I discuss on pages 140-142.

    -Paul

  • 02-21-2010 11:03 AM In reply to

    • Golfgazoo
    • Top 25 Contributor
    • Joined on 02-06-2010
    • Santa Cruz
    • Posts 3

    Re: Question about ABG-VBA

     I used to program in Basic (Applesoft for the Apple II+), and I remember that instead of using the Input command, which required the use of the Enter key to complete the input, we could poll a certain memory location called the keyboard strobe that would not only indicate that a key was pressed but provided the code of which key was pressed. Then an action could be taken with a single key press (without having to use the Enter key as well); but it also provided the programmer a easy way to error-trap entries (e.g., trap alpha keys if a number was expected.) I was wondering if VBA had such a command, not to start a procedure, but when asking for input from a user.

  • 02-21-2010 5:05 PM In reply to

    • Paul
    • Top 10 Contributor
    • Joined on 09-19-2007
    • Toronto
    • Posts 288

    Re: Question about ABG-VBA

    Okay, I see what you're doing. VBA doesn't have a direct way of doing that, but it can hook into the Windows API, which has functions for capturing keypresses. It's a bit advanced, but not too bad. The following page has some code you should be able to use:

    http://www.informit.com/articles/article.aspx?p=366892&seqNum=4

    -Paul

  • 02-21-2010 9:21 PM In reply to

    • Golfgazoo
    • Top 25 Contributor
    • Joined on 02-06-2010
    • Santa Cruz
    • Posts 3

    Re: Question about ABG-VBA

     Thank you, Paul. Let me play with this a bit and get back with you if I have any questions.

Page 1 of 1 (5 items)
Copyright © 2008 Logophilia Limited and Paul McFedries
Powered by Community Server (Commercial Edition), by Telligent Systems