Keyboard.AsyncKeydown sorrows (Real Studio network user group Mailinglist archive)

Back to the thread list
Previous thread: RB 4.5.2 and latest iBook + MacOS X 1.2 [and off too]
Next thread: DEL, DLE, Backspace question


Keyboard.AsyncKeydown sorrows   -   Mike Richardson
   Re: Keyboard.AsyncKeydown sorrows   -   Ricardo Rojas
    Re: Keyboard.AsyncKeydown sorrows   -   Thomas Reed
     Re: Keyboard.AsyncKeydown sorrows   -   ern modern
      Re: Keyboard.AsyncKeydown sorrows   -   Joseph J. Strout
     Re: Keyboard.AsyncKeydown sorrows   -   john roberts
      Re: Keyboard.AsyncKeydown sorrows   -   Thomas Reed

Keyboard.AsyncKeydown sorrows
Date: 12.12.02 06:47 (Wed, 11 Dec 2002 23:47:16 -0600)
From: Mike Richardson
I have the ASCII code for a key. It could be any key. I want to see if
that key is pressed. How do I do this using Keyboard.AsyncKeyDown?

PS: I need some actual code, because I don't know much about taking a
toolbox call and making it useful. Also, I use RB 3.5.

---
A searchable archive of this list is available at:
<http://dbserver.realsoftware.com/KBDB/search.php>

Unsubscribe:
<mailto:<email address removed>>

Subscribe to the digest:
<mailto:<email address removed>>

Re: Keyboard.AsyncKeydown sorrows
Date: 13.12.02 02:02 (Thu, 12 Dec 2002 21:02:15 -0400)
From: Ricardo Rojas
Mike Richardson, <email address removed>, wrote:

1st post
>I have the ASCII code for a key. It could be any key. I want to see if
>that key is pressed. How do I do this using Keyboard.AsyncKeyDown?
>
>PS: I need some actual code, because I don't know much about taking a
>toolbox call and making it useful. Also, I use RB 3.5.

Hi Mike. I'm going to take a wild guess here and assume you are a newbie.
No offense.

Usually you catch which keys are pressed in the keyDown event and usually
you don't need the keyboard.asyncKeyDown function there. Let's say you
want to know if the user pressed the "h" key.

so in the keyDown event you put the following:

if asc(key) = 104 then
msgBox "User pressed " + key //your code here
end

I could be of more help if I knew what you want to accomplish.

>Also, I don't have any REALbasic books and can't get any soon, so
>telling me page blah blah in book blah won't help me much.

Well, no blah page, but if you press command-1 it will bring the online
help to the screen. Very handy and with working examples.

HTH,
>>>®<<

---
A searchable archive of this list is available at:
<http://dbserver.realsoftware.com/KBDB/search.php>

Unsubscribe:
<mailto:<email address removed>>

Subscribe to the digest:
<mailto:<email address removed>>

Re: Keyboard.AsyncKeydown sorrows
Date: 13.12.02 17:00 (Fri, 13 Dec 2002 10:00:26 -0600)
From: Thomas Reed
>Usually you catch which keys are pressed in the keyDown event and usually
>you don't need the keyboard.asyncKeyDown function there.

There are reasons to use AsyncKeyDown, though. However, since
AsyncKeyDown takes key codes rather than ASCII character codes,
you're out of luck with trying to use ASCII with it. There may be
some way to convert an ASCII character into a key code appropriately
for the keyboard in use, but I don't know what that is.

>Let's say you
>want to know if the user pressed the "h" key.
>
>so in the keyDown event you put the following:
>
> if asc(key) = 104 then
> msgBox "User pressed " + key //your code here
> end

Why on Earth would you do that? It would be much more effective to do:

if key = "h" then
MsgBox "User pressed " + key //your code here
end if

There are times to use the asc() function, but finding out if the key
pressed was "h" is not one of them.

Re: Keyboard.AsyncKeydown sorrows
Date: 13.12.02 19:49 (Fri, 13 Dec 2002 13:49:58 -0500)
From: ern modern
I think one of the problems is that ASCII characters don't map
one-to-one with keycodes. Example, E and e are ascii 69 and 101 and
that key's keycode is &H0E...and I am not even sure that that relation
holds in some foreign keyboards. So I'm not sure why anyone would try
doing it that way.

On Friday, December 13, 2002, at 11:00 AM, Thomas Reed wrote:

>> Usually you catch which keys are pressed in the keyDown event and
>> usually
>> you don't need the keyboard.asyncKeyDown function there.
>
> There are reasons to use AsyncKeyDown, though. However, since
> AsyncKeyDown takes key codes rather than ASCII character codes, you're
> out of luck with trying to use ASCII with it. There may be some way
> to convert an ASCII character into a key code appropriately for the
> keyboard in use, but I don't know what that is.

---
A searchable archive of this list is available at:
<http://dbserver.realsoftware.com/KBDB/search.php>

Unsubscribe:
<mailto:<email address removed>>

Subscribe to the digest:
<mailto:<email address removed>>

Re: Keyboard.AsyncKeydown sorrows
Date: 13.12.02 20:01 (Fri, 13 Dec 2002 11:01:29 -0800)
From: Joseph J. Strout
At 1:49 PM -0500 12/13/02, ern modern wrote:

>I think one of the problems is that ASCII characters don't map
>one-to-one with keycodes. Example, E and e are ascii 69 and 101 and
>that key's keycode is &H0E...and I am not even sure that that
>relation holds in some foreign keyboards.

It's not even true on my keyboard; my "e" key is key code &h02. So
no, you can't assume any constant relationship between ASCII codes
and key codes (with a few exceptions, like the Esc key, which I think
is pretty constant).

There are indeed ways to look up the ASCII code for a given key code,
or vice versa. But they involve declares into the Mac or Win32
toolbox.

Best,
- Joe

Re: Keyboard.AsyncKeydown sorrows
Date: 13.12.02 20:15 (Fri, 13 Dec 2002 14:15:23 -0500)
From: john roberts
on 12/13/02 11:00 AM, Thomas Reed at <email address removed> wrote:

>> Let's say you
>> want to know if the user pressed the "h" key.
>>
>> so in the keyDown event you put the following:
>>
>> if asc(key) = 104 then
>> msgBox "User pressed " + key //your code here
>> end
>
> Why on Earth would you do that? It would be much more effective to do:

Because that differentiates between "h" and "H"

>
> if key = "h" then
> MsgBox "User pressed " + key //your code here
> end if

which this won't.
>
> There are times to use the asc() function, but finding out if the key
> pressed was "h" is not one of them.

It depends ...

John Roberts

---
A searchable archive of this list is available at:
<http://dbserver.realsoftware.com/KBDB/search.php>

Unsubscribe:
<mailto:<email address removed>>

Subscribe to the digest:
<mailto:<email address removed>>

Re: Keyboard.AsyncKeydown sorrows
Date: 13.12.02 20:44 (Fri, 13 Dec 2002 13:44:28 -0600)
From: Thomas Reed
> >> if asc(key) = 104 then
>>> msgBox "User pressed " + key //your code here
>>> end
>>
>> Why on Earth would you do that? It would be much more effective to do:
>
>Because that differentiates between "h" and "H"

True, though I would argue this makes it even worse as a general
example, which is how I interpreted this. However, you're right that
there are always times for everything, and thus there very well may
be a use for the above code.