Articles Archive
Articles Search
Director Wiki
 

Keyfinder Utility

November 26, 2000
by Pat McClellan

Dear Multimedia Handyman

I've been making games in Director, but I've looked everywhere and I can't find how to control the games with keys. I know the commands to use but I don't have the keycode numbers for each key. I'm pretty sure that they are the same as they were back in DOS days but I haven't seen a chart of them for ages.

Andrew

Dear Andrew,

I've never actually had a chart of them, but it only took me a couple of minutes to come up with a handy utility for you to use. As mentioned before in this column, Director is ideal for building your own tools to assist your Director development. I create them as dir files and then drop them into the Xtras folder. They, just open them from the Xtras menu when you need them.

To create your keyfinder utility, I started with two Field members on the Stage: one named "keyname"; the other, "keycodeNum". Next, whip up a keyDownScript handler like this:

on startMovie

  set the keyDownScript to "showInfo"
  member("keyname").text = " "
  member("keycodeNum").text = " "

end


on showInfo

  member("keycodeNum").text = string(the keycode)

  case the keyCode of
    123: keyname = "left"
    124: keyname = "right"
    125: keyname = "down"
    126: keyname = "up"
    otherwise
      keyname = string(the key)
  end case

  member("keyname").text = keyname

end

The startMovie handler blanks out any residual values in the fields and sets the keyDownScript to the showInfo handler. The showInfo handler puts the keycode into the text of the keycodeNum member and puts the keyname into the keyname member. I added a case statement to interpret the arrow keys' names because these are among the most frequently needed keycodes (at least in the area of games.)

A sample Director 7 movie is available for download in Mac or Windows format.

If you need a refresher on the code for using the keys to control your game, take a look at my article on Steering with Momentum. In that article, I demonstrate how to use key combinations to achieve thrust and directional control at the same time.

I'd be remiss if I didn't recommend Gary Rosenzweig's book, Advanced Lingo for Games. This book is exceptional, although the title is a bit misleading. Gary explains things so well that I recommend the book to any serious beginner (so it's not just for advanced users), and the Lingo you learn here is applicable to any type of Director work.

Good luck with your project.

Patrick McClellan is Director Online's co-founder. Pat is Vice President, Managing Director for Jack Morton Worldwide, a global experiential marketing company. He is responsible for the San Francisco office, which helps major technology clients to develop marketing communications programs to reach enterprise and consumer audiences.

Copyright 1997-2017, Director Online. Article content copyright by respective authors.