Introducing the “Welcome to Xojo” Bundle!

New to Xojo and looking for guidance? We've put together a terrific bundle to welcome you! Xojo Bundle

This bundle includes six back issues of the magazine -- all of year 17 in printed book and digital formats -- plus a one-year subscription (beginning with 18.1) so you'll be learning all about Xojo for the next year. It's the perfect way to get started programming with Xojo. And you save as much as $35 over the non-bundle price!

This offer is only available for a limited time as supplies are limited, so hurry today and order this special bundle before the offer goes away!

Article Preview

Buy Now

Issue 3.2


Got Keys?

Cross-Platform, Asynchronous Keyboard Input

Issue: 3.2 (November/December 2004)
Author: Lars Jensen
Author Bio: Lars Jensen first fretted over asynchronous keystrokes on the DEC PDP-11/70 in 1977. (Hint: use the QIO function to fake it...)
Article Description: No description available.
Article Length (in bytes): 29,816
Starting Page Number: 26
Article Number: 3212
Resource File(s):

Download Icon 3212.zip Updated: 2013-03-11 19:07:58

Related Web Link(s):


Excerpt of article text...

Most keyboard handling in REALbasic is synchronous; that is, you wait for a key-related event to occur, and you handle it without knowing whether or not the key has been released by the time your code executes. However, if you're modifying the behavior of a standard control, or programming a custom control or a game, you might need to know whether a key is pressed at the moment your code is executing, without waiting for the next keyboard event. That's called asynchronous keyboard input.

A common example is using the Shift key to constrain a drag to a horizontal or vertical axis. REALbasic lets us check the status of all Shift keys as a group, using the built-in Keyboard.AsyncShiftKey function. There are similar functions for the other common modifier keys.

But what if you want to see if only the left or right Shift key is down, or check the status of an arbitrary key on the keyboard? This kind of thing can get tricky if you want your code to run on any operating system, or even on different keyboard layouts within a single operating system.

In this article, we'll devise code that we can drop into any project to access the keyboard easily, efficiently, and asynchronously, in a platform-neutral way. We'll use this code in a diagnostic tool that can reveal what a given keyboard is capable of. And we'll explore some pitfalls in trying to write once and run anywhere. All of this will take place in "pure" REALbasic -- no plugins or Declares needed. (OK, there's one Declare, but it's optional...)

Keys, Keycodes, and Characters

See the 'A' key on your keyboard? When you press it, the keyboard doesn't send an 'A' character to the operating system. Instead, it sends a keycode -- a number between 0 and 127 (inclusive) that identifies the switch under the physical piece of plastic that your finger pressed, regardless of what happens to be printed on the key or where it's located.

...End of Excerpt. Please purchase the magazine to read the full article.