Discussion:
NSEvent keyCode
Guy English
2000-06-17 20:10:38 UTC
Permalink
Hi,

What exactly does NSEvent keyCode return? Is it the keyboard
hardwares scan code or something from the HID system? My application is a
game and I want to map operating system key codes to the codes we use in
the game. The AppKit docs say the return value is hardware dependant but I
can't find much else about it. If it is hardware dependant do ADB and USB
keyboards give off different scan codes?

Thanks
Guy
Joakim Arfvidsson NV98ATe
2000-06-19 05:47:21 UTC
Permalink
Post by Guy English
Hi,
What exactly does NSEvent keyCode return? Is it the keyboard
hardwares scan code or something from the HID system? My application is a
game and I want to map operating system key codes to the codes we use in
the game. The AppKit docs say the return value is hardware dependant but I
can't find much else about it. If it is hardware dependant do ADB and USB
keyboards give off different scan codes?
It's different on a keyboard-model basis.

I'm the author of MacBlox for DP4, and I have had the same problem. If
you think the same way some software developers do and shoot for "the
90 percent", you can safely assume the scan codes are identical. All
Apple's late USB and ADB keyboards have (almost, I believe) the same
scan codes. For the arrows and space I have confirmed this for Extended
I, II, Adjustable and USB.

I did see something very interesting when I dug around in the
Frameworks. I don't remember where, but I found a text file appearantly
containing descriptions for all Apple keyboards, including scan codes
and physical placement! That might be something. If you find out how to
use it, please tell me!
Joakim Arfvidsson NV98ATe
2000-06-19 06:50:51 UTC
Permalink
I forgot to mention the one exception I have found. One guy mailed me
and said arrows wasn't working on his "Apple Keyboard". That's Apple's
first ADB keyboard, shipped with the SE.
Guy English
2000-06-20 03:07:41 UTC
Permalink
Post by Joakim Arfvidsson NV98ATe
It's different on a keyboard-model basis.
Great.
Post by Joakim Arfvidsson NV98ATe
I'm the author of MacBlox for DP4, and I have had the same problem. If
you think the same way some software developers do and shoot for "the
90 percent", you can safely assume the scan codes are identical. All
Apple's late USB and ADB keyboards have (almost, I believe) the same
scan codes. For the arrows and space I have confirmed this for Extended
I, II, Adjustable and USB.
That's actually not such a bad solution for me because my games minimum
requirements would limit it to machines with late model keyboards anyway.
What I don't like though is the idea that Apple may change the scan codes
on future keyboards, breaking my app.
Post by Joakim Arfvidsson NV98ATe
I did see something very interesting when I dug around in the
Frameworks. I don't remember where, but I found a text file appearantly
containing descriptions for all Apple keyboards, including scan codes
and physical placement! That might be something. If you find out how to
use it, please tell me!
I assume you mean the files in /System/Library/Keyboards? The .keyboard
files describe the visual layout of the keyboard like you see in the
keymapping app. I assume the hex number is the scan code for the key at
that position. By parsing that file and using [NSEvent keyCode] is seems
like you should be able to map a physical key on the keyboard to some
action in your app. You need to know what keyboard your user has but I'm
sure you can find that out. Thats all way too much for me, though. I just
want the Cocoa version of Windows, VK_F1, etc, or XWindows XK_F1.

Meanwhile, NSF1FunctionKey and friends are defined in AppKit/NSEvent.h.
When are these returned by the system? Are they the result of [NSEvent
keyCode]? I'd like to know how the Quake/Hertic/Doom ports handle this kind
of stuff.

Thanks,
Guy
Frederic Stark
2000-06-20 09:35:36 UTC
Permalink
Post by Guy English
Post by Joakim Arfvidsson NV98ATe
It's different on a keyboard-model basis.
Great.
Of course. This is that way by definition.
Post by Guy English
Post by Joakim Arfvidsson NV98ATe
I'm the author of MacBlox for DP4, and I have had the same
problem. If
Post by Guy English
Post by Joakim Arfvidsson NV98ATe
you think the same way some software developers do and shoot for "the
90 percent", you can safely assume the scan codes are identical. All
Apple's late USB and ADB keyboards have (almost, I believe) the same
scan codes. For the arrows and space I have confirmed this for
Extended
Post by Guy English
Post by Joakim Arfvidsson NV98ATe
I, II, Adjustable and USB.
That's actually not such a bad solution for me because my games
minimum
Post by Guy English
requirements would limit it to machines with late model keyboards
anyway.
Post by Guy English
What I don't like though is the idea that Apple may change the
scan codes
Post by Guy English
on future keyboards, breaking my app.
Apple will change the scan codes. They are done for that. They are
tied to the hardware.

[crunch]
Post by Guy English
I assume you mean the files in /System/Library/Keyboards? The
.keyboard
Post by Guy English
files describe the visual layout of the keyboard like you see in the
keymapping app. I assume the hex number is the scan code for the
key at
Post by Guy English
that position. By parsing that file and using [NSEvent keyCode] is
seems
Post by Guy English
like you should be able to map a physical key on the keyboard to some
action in your app. You need to know what keyboard your user has
but I'm
Post by Guy English
sure you can find that out. Thats all way too much for me, though.
I just
Post by Guy English
want the Cocoa version of Windows, VK_F1, etc, or XWindows XK_F1.
Meanwhile, NSF1FunctionKey and friends are defined in
AppKit/NSEvent.h.
Post by Guy English
When are these returned by the system? Are they the result of
[NSEvent
Post by Guy English
keyCode]? I'd like to know how the Quake/Hertic/Doom ports handle
this kind
Post by Guy English
of stuff.
Why do you want to go down to key codes ? I suspect you are (or I
am) a bit confused on the issue. A press of F1 generates the
following keyDown: event on my machine (OSXS)

type=KeyDown loc=(0,0) time=10531.3 flags=0x800000 win=0 winNum=4
ctxt=0x15880 chars="\Uf704" unmodchars="\Uf704" repeat=0 keyCode=122

As you may see "\Uf704" is exactly NSF1FunctionKey. This _unicode_
character represents F1. So what is your problem ?

I didn't recall your first mail, but you can go pretty far by using
NSKeyDown/NSKeyUp and NSFlagsChanged.

Tell me is I miss something.

Cheers,

--fred
Guy English
2000-06-20 23:22:31 UTC
Permalink
Hi,
Post by Frederic Stark
Post by Guy English
Post by Joakim Arfvidsson NV98ATe
It's different on a keyboard-model basis.
Great.
Of course. This is that way by definition.
True enough.
Post by Frederic Stark
Post by Guy English
Meanwhile, NSF1FunctionKey and friends are defined in AppKit/NSEvent.h.
When are these returned by the system? Are they the result of [NSEvent
keyCode]? I'd like to know how the Quake/Hertic/Doom ports handle this kind
of stuff.
Why do you want to go down to key codes ? I suspect you are (or I am) a
bit confused on the issue. A
Post by Frederic Stark
press of F1 generates the following keyDown: event on my machine (OSXS)
type=KeyDown loc=(0,0) time=10531.3 flags=0x800000 win=0 winNum=4 ctxt=0x15880
chars="\Uf704" unmodchars="\Uf704" repeat=0 keyCode=122
As you may see "\Uf704" is exactly NSF1FunctionKey. This _unicode_
character represents
Post by Frederic Stark
F1. So what is your problem ?
I am confused on the issue. Basically I had abstracted the operating
systems event loop out of my game and simply wanted to poll the event queue
for the next event. I looked at it today at work and changed the Windows
and Linux system code to callback an idle handler when there are no
messages waiting. I'm going to change the OSX stuff now and am going to use
a timer at a very fast fire rate to do the same thing. I'll subclass a
view and use the keyDown messages to jam the input into my games keyboard
buffer.
Post by Frederic Stark
I didn't recall your first mail, but you can go pretty far by using
NSKeyDown/NSKeyUp and
Post by Frederic Stark
NSFlagsChanged.
Tell me is I miss something.
Nope, it's me. I'm happier with doing it this way because it makes the
code for the OSX port look much more like a normal Cocoa program. Unless it
turns out to be dog slow for some reason I'm happy using the frameworks.
Unless I grab the mach messages from the WindowServer directly... :)
Post by Frederic Stark
Cheers,
--fred
Thanks,
Guy
Herb Petschauer
2000-06-21 20:12:04 UTC
Permalink
Hey, anyone had any luck posting a modifier key. Say I want to post
a control key DOWN while the user is clicking. If I post using the
virtual code for the control key (uh... 0x3b??) I get an invisible
ASCII character. I seem to remember that there are different virtual
codes for USB? Probably time to grep the headers, any head start
advice?

Thanks,

H.
================================================
- OS X, so cunning you could put a tail on it and call it a weasel.
With apologies to Black Adder fans everywhere...

Herb Petschauer
Wacom Technology Corp.
***@wacom.com
================================================
Frederic Stark
2000-06-21 11:51:18 UTC
Permalink
Post by Guy English
Post by Frederic Stark
So what is your problem ?
I am confused on the issue. Basically I had abstracted the operating
systems event loop out of my game and simply wanted to poll the
event queue
Post by Guy English
for the next event.
Great. What about:

[NSApplication nextEventMatchingMask:untilDate:inMode:dequeue:];

[crunch]
Post by Guy English
Nope, it's me. I'm happier with doing it this way because it makes
the
Post by Guy English
code for the OSX port look much more like a normal Cocoa program.
Unless it
Post by Guy English
turns out to be dog slow for some reason I'm happy using the
frameworks.
Post by Guy English
Unless I grab the mach messages from the WindowServer directly... :)
Read them from /dev/ev0 (Headers/bsd/sys/ev.h) :-)
[This is a joke]

Cheers,

--fred
Jonah Petri
2000-06-21 13:48:42 UTC
Permalink
Hello:
I've been trying to learn some Java Cocoa programming, but I'm running into a
bit of a problem. For some reason, when I use the new Project Builder (not the
ProjectBuilderWO, a.k.a. ProjectBuilder of DP3), none of my code works
properly.
I have a nib file, with an instantiated class, which has 2 outlets and 1
action. It's basically the same setup as the TemperatureConverter example
Project. When I compile my code, it does so with no errors. However, when I
run my code, I get this message:

Jun 21 11:45:53 DistConvert[2008] Unknown class `DistConv' in nib file, using
`NSObject' instead.
Jun 21 11:45:54 DistConvert[2008] Could not connect the action convert: to
target of class NSObject
Jun 21 11:45:54 DistConvert[2008] Could not connect the action convert: to
target of class NSObject

Here's the catch: on a hunch, i tried using ProjectBuilderWO to make my
project, and it worked fine! Am I missing something basic in the new
ProjectBuilder? Or is it not complete enough, and I should simply use
ProjectBuilderWO?

Thanks for any and all help!

Jonah
Robert Cerny
2000-06-21 14:09:20 UTC
Permalink
Well,
it's not so big problem. Go to
<http://www.omnigroup.com/community/developer/mailinglists/macosx-dev/> and
check archives, There is a thread with PBX + Java. You can find an answer
there...

HTH
--
Robert Cerny
**************************
Robert Cerny
DataLine Technology Ltd.
Ceskomoravska 15
190 00 Prague 9
Czech Republic
mailto:***@dlt.cz
http://www.dlt.cz
ICQ: 24277867
PGP public keyID: 0x869BE348
Date: Wed, 21 Jun 2000 11:48:33 -0400
Subject: Newbie dev question
I've been trying to learn some Java Cocoa programming, but I'm running into a
bit of a problem. For some reason, when I use the new Project Builder (not
the
ProjectBuilderWO, a.k.a. ProjectBuilder of DP3), none of my code works
properly.
I have a nib file, with an instantiated class, which has 2 outlets and 1
action. It's basically the same setup as the TemperatureConverter example
Project. When I compile my code, it does so with no errors. However, when I
Jun 21 11:45:53 DistConvert[2008] Unknown class `DistConv' in nib file, using
`NSObject' instead.
Jun 21 11:45:54 DistConvert[2008] Could not connect the action convert: to
target of class NSObject
Jun 21 11:45:54 DistConvert[2008] Could not connect the action convert: to
target of class NSObject
Here's the catch: on a hunch, i tried using ProjectBuilderWO to make my
project, and it worked fine! Am I missing something basic in the new
ProjectBuilder? Or is it not complete enough, and I should simply use
ProjectBuilderWO?
Thanks for any and all help!
Jonah
_______________________________________________
MacOSX-dev mailing list
http://www.omnigroup.com/mailman/listinfo/macosx-dev
Frederic Stark
2000-06-22 11:18:27 UTC
Permalink
Post by Herb Petschauer
Hey, anyone had any luck posting a modifier key.
What do you mean ? Posting a new event ? Under Cocoa ? Carbon ?
Inside an app ? To another app ?
Herb Petschauer
2000-06-22 15:19:28 UTC
Permalink
Actually your snippet confirmed my suspicion, thanks but I'll carry on...
Post by Frederic Stark
What do you mean ? Posting a new event ? Under Cocoa ? Carbon ?
Inside an app ? To another app ?
Frederic Stark
2000-06-23 09:46:19 UTC
Permalink
Post by Herb Petschauer
Actually your snippet confirmed my suspicion, thanks but I'll
carry on...

I realize that I have been a little rude. You are not supposed to
know the in and out of cocoa from start.
Post by Herb Petschauer
Post by Frederic Stark
What do you mean ? Posting a new event ? Under Cocoa ? Carbon ?
Inside an app ? To another app ?
Loading...