TweetFollow Us on Twitter

Jun 95 Tips
Volume Number:11
Issue Number:6
Column Tag:Tips & Tidbits

Tips & Tidbits

By Neil Ticktin, Editor-in-Chief with special thanks to Steve Sisak

Note: Source code files accompanying article are located on MacTech CD-ROM or source code disks.

TIP OF THE MONTH

GetKeys From Within MacsBug

There is a routine in the Macintosh toolbox called GetKeys. This routine is great for game programmers who want a reasonably fast way to read the keyboard, without using (slower) events. The problem for C and C++ programmers using this routine is that the KeyMap type is a Pascal packed array. Each bit of the packed array is designated to a certain key, the bit is set to 1 if the key is down, and set to zero if the key is up. This array takes up 16 bytes (128 bits). C cannot access the elements of the packed array like a normal array, so the programmer has to mask out some bits to get the result that he/she wants. There is a desk accessory named “GetKeys,” that is made just for this case. The problem is, you might not be on a machine with that program on it.

Good thing MacsBug is able to help us. Here is how you locate the bit for the letter “M”: go into MacsBug and type in “dm KeyMap”, but don’t hit return just yet. Now strike the escape key, this should swap the screen. Press and hold down the letter “M” on your keyboard, this should swap the screen back. Now, while still holding down “M”, press return. This is what you should see:

Displaying memory from 0174:

  00000174  0000 0000 0040 0000  0000 0000 0000 0000       •••••@••••••••••

The number “00000174” is the address of the KeyMap global variable. The next set of numbers “0000 0000” is the first element of the C version of the array, in other words it’s: “keyMap[0]”. The next set of numbers “0040 0000” is the second element of the array, keyMap[1]. The next group of 8 hexadecimal digits is the third element (keyMap[2]), and the last group of 8 hexadecimal digits is the fourth element (keyMap[3]). The series of bullets is what the array looks like in ASCII form. In the second group (“0040 0000”) there is a 4 in the midst of all of those zeros. This is the bit that is set to 1 whenever the “M” key is held down. So, to see if the “M” is down from within C we will do this:

 KeyMap keyMap;
 GetKeys( keyMap );

 if( keyMap[1] & 0x00400000 )
 {  DoMKeyDown();
 }

That’s all there is to it!

Macneil Shonle, Yarmouth Maine
MacneilS@aol.com

Almost, But Not Quite

In his tip (MacTech, March 1995 issue, page 67), Jeff Beeghly assumes items #1 and #2 to be respectively the default and the cancel items. That is not always true: in fact these may even change between subsequent calls to the same dialog/alert if the programmer used “SetDialogDefaultItem” and “SetDialogCancelItem” before calling ModalDialog or set the “ALRT stage info” in ResEdit for the alert box. The safest way to find the default item is to look at the “aDefItem” field of the DialogRecord that is passed to the the custom modal filter procedure.

Moreover, I think it is best to let the original filter procedure track standard events we’re not interested in, by calling it via “StdFilterProc” from our custom filter proc and then returning its return value to the application.

- Luigi Belverato

 

Community Search:
MacTech Search:

Software Updates via MacUpdate

Drop to GIF 1.28 - Drag-and-drop creatio...
Drag to GIF means zero-click movie-to-GIF conversion. Select a folder to watch and every movie saved or moved into that folder will be converted to an animated GIF. Features Dragging - Drag a movie... Read more
BetterTouchTool 3.158 - Customize multi-...
BetterTouchTool adds many new, fully customizable gestures to the Magic Mouse, Multi-Touch MacBook trackpad, and Magic Trackpad. These gestures are customizable: Magic Mouse: Pinch in / out (zoom)... Read more
NeoFinder 7.4.1 - Catalog your external...
NeoFinder (formerly CDFinder) rapidly organizes your data, either on external or internal disks, or any other volumes. It catalogs and manages all your data, so you stay in control of your data... Read more
Tunnelblick 3.8.0 - GUI for OpenVPN.
Tunnelblick is a free, open source graphic user interface for OpenVPN on OS X. It provides easy control of OpenVPN client and/or server connections. It comes as a ready-to-use application with all... Read more
Tweetbot 3 for Twitter 3.3.1 - Popular T...
Tweetbot is a full-featured OS X Twitter client with a lot of personality. Whether it's the meticulously-crafted interface, sounds and animation, or features like multiple timelines and column views... Read more
Monosnap 3.5.9 - Versatile screenshot ut...
Monosnap lets you capture screenshots, share files, and record video and .gifs. Features Capture Capture full screen, just part of the screen, or a selected window Make your crop area pixel... Read more
Monosnap 3.5.9 - Versatile screenshot ut...
Monosnap lets you capture screenshots, share files, and record video and .gifs. Features Capture Capture full screen, just part of the screen, or a selected window Make your crop area pixel... Read more
Tweetbot 3 for Twitter 3.3.1 - Popular T...
Tweetbot is a full-featured OS X Twitter client with a lot of personality. Whether it's the meticulously-crafted interface, sounds and animation, or features like multiple timelines and column views... Read more
Tunnelblick 3.8.0 - GUI for OpenVPN.
Tunnelblick is a free, open source graphic user interface for OpenVPN on OS X. It provides easy control of OpenVPN client and/or server connections. It comes as a ready-to-use application with all... Read more
Bookends 13.2.5 - Reference management a...
Bookends is a full-featured bibliography/reference and information-management system for students and professionals. Bookends uses the cloud to sync reference libraries on all the Macs you use.... Read more

Latest Forum Discussions

See All

Void Tyrant guide - Tips and tricks for...
Void Tyrant continues to get a lot of play in these parts. Probably because the game is just so deep and varied. The next stop on our guide series for Void Tyrant is class-specific guides. First up is the Knight, as it’s the first class anyone has... | Read more »
Summon beasts and battle evil in epic re...
Imagine a tale of conlict between factions of good and evil, where rogueish heroes summon beasts to aid them in them in warfare and courageously battle dragons over fields of scorched earth and brimstone - that's exactly the essence of epic fantasy... | Read more »
Upcoming visual novel Arranged shines a...
If you’re in the market for a new type of visual novel designed to inform and make you think deeply about its subject matter, then Arranged by Kabuk Games could be exactly what you’re looking for. It’s a wholly unique take on marital traditions in... | Read more »
TEPPEN guide - The three best decks in T...
TEPPEN’s unique take on the collectible card game genre is exciting. It’s just over a week old, but that isn’t stopping lots of folks from speculating about the long-term viability of the game, as well as changes and additions that will happen over... | Read more »
Intergalactic puzzler Silly Memory serve...
Recently released matching puzzler Silly Memory is helping its fans with their intergalactic journeys this month with some very special offers on in-app purchases. In case you missed it, Silly Memory is the debut title of French based indie... | Read more »
TEPPEN guide - Tips and tricks for new p...
TEPPEN is a wild game that nobody asked for, but I’m sure glad it exists. Who would’ve thought that a CCG featuring Capcom characters could be so cool and weird? In case you’re not completely sure what TEPPEN is, make sure to check out our review... | Read more »
Dr. Mario World guide - Other games that...
We now live in a post-Dr. Mario World world, and I gotta say, things don’t feel too different. Nintendo continues to squirt out bad games on phones, causing all but the most stalwart fans of mobile games to question why they even bother... | Read more »
Strategy RPG Brown Dust introduces its b...
Epic turn-based RPG Brown Dust is set to turn 500 days old next week, and to celebrate, Neowiz has just unveiled its biggest and most exciting update yet, offering a host of new rewards, increased gacha rates, and a brand new feature that will... | Read more »
Dr. Mario World is yet another disappoin...
As soon as I booted up Dr. Mario World, I knew I wasn’t going to have fun with it. Nintendo’s record on phones thus far has been pretty spotty, with things trending downward as of late. [Read more] | Read more »
Retro Space Shooter P.3 is now available...
Shoot-em-ups tend to be a dime a dozen on the App Store, but every so often you come across one gem that aims to shake up the genre in a unique way. Developer Devjgame’s P.3 is the latest game seeking to do so this, working as a love letter to the... | Read more »

Price Scanner via MacPrices.net

13″ 1.8GHz MacBook Air on sale again for only...
Amazon has the 2017 13″ 1.8GHz/128GB MacBook Air on sale today for only $749.99 shipped. That’s $250 off Apple’s original MSRP for this model and the cheapest MacBook Air available from any Apple... Read more
Apple’s $1489 clearance price on refurbished...
Apple has Certified Refurbished 2018 13″ 2.3GHz 4-Core Touch Bar MacBook Pros available starting at $1489. Apple’s one-year warranty is included, shipping is free, and each MacBook has a new outer... Read more
New 2019 13″ 2.4GHz 4-Core MacBook Pros on sa...
Apple resellers B&H Photo and Amazon are offering the new 2019 13″ 2.4GHz 4-Core Touch Bar MacBook Pros for $150 off Apple’s MSRP. These are the same MacBook Pros sold by Apple in its retail and... Read more
B&H drops prices another $50 on clearance...
B&H Photo has dropped prices on clearance 2018 13″ MacBook Airs by a further $50 with models now available for $250 off Apple’s original MSRP. Overnight shipping, or expedited shipping, is free... Read more
Find the best sales & lowest prices on Ap...
Our Apple award-winning price trackers are the best place to look for the best sales and lowest prices on Apple gear. Scan our price trackers for the latest information on sales, bundles, and... Read more
Apple has clearance 2018 13″ MacBook Airs now...
Apple has Certified Refurbished 2018 13″ MacBook Airs available starting at only $849. Each MacBook features a new outer case, comes with a standard Apple one-year warranty, and is shipped free. The... Read more
Save $400 on the 8-Core iMac Pro today at Ama...
Amazon has the base 8-core iMac Pro on sale today for $4599 including free shipping. Their price is $400 off Apple’s MSRP, and it’s the currently lowest price available for an iMac Pro. For the... Read more
Flash sale! New 11″ 1TB WiFi iPad Pros for th...
Amazon has the 11″ 1TB WiFi iPad Pro on sale today for only $1199.99 including free shipping. Their price is $350 off Apple’s MSRP for this model, and it’s the lowest price ever for a 1TB 11″ iPad... Read more
Weekend Deal: 2018 13″ MacBook Airs starting...
B&H Photo has clearance 2018 13″ MacBook Airs available starting at only $999 with all models now available for $200 off Apple’s original MSRP. Overnight shipping, or expedited shipping, is free... Read more
Apple has clearance 10.5″ iPad Pros available...
Apple has Certified Refurbished 2017 10.5″ iPad Pros available starting at $469. An Apple one-year warranty is included with each iPad, outer shells are new, and shipping is free: – 64GB 10″ iPad Pro... Read more

Jobs Board

Best Buy *Apple* Computing Master - Best Bu...
**711495BR** **Job Title:** Best Buy Apple Computing Master **Job Category:** Store Associates **Location Number:** 000882-Waterfront-Store **Job Description:** The Read more
Best Buy *Apple* Computing Master - Best Bu...
**711597BR** **Job Title:** Best Buy Apple Computing Master **Job Category:** Sales **Location Number:** 000873-Colma CA-Store **Job Description:** **What does a Read more
Best Buy *Apple* Computing Master - Best Bu...
**711346BR** **Job Title:** Best Buy Apple Computing Master **Job Category:** Store Associates **Location Number:** 001095-Chesterfield-Store **Job Description:** Read more
Best Buy *Apple* Computing Master - Best Bu...
**704899BR** **Job Title:** Best Buy Apple Computing Master **Job Category:** Sales **Location Number:** 000135-Pleasant Hill-Store **Job Description:** **What does Read more
Best Buy *Apple* Computing Master - Best Bu...
**707083BR** **Job Title:** Best Buy Apple Computing Master **Job Category:** Sales **Location Number:** 000045-Rockford-Store **Job Description:** **What does a Read more
All contents are Copyright 1984-2011 by Xplain Corporation. All rights reserved. Theme designed by Icreon.