home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #16 / NN_1992_16.iso / spool / comp / sys / next / programm / 5150 < prev    next >
Encoding:
Text File  |  1992-07-21  |  2.1 KB  |  84 lines

  1. Path: sparky!uunet!dtix!darwin.sura.net!mips!news.cs.indiana.edu!umn.edu!news
  2. From: rowley@leghorn.cs.umn.edu. (Tim Rowley)
  3. Newsgroups: comp.sys.next.programmer
  4. Subject: Keyboard input
  5. Keywords: keyboard, events
  6. Message-ID: <1992Jul21.191759.3408@news2.cis.umn.edu>
  7. Date: 21 Jul 92 19:17:59 GMT
  8. Sender: news@news2.cis.umn.edu (Usenet News Administration)
  9. Distribution: usa
  10. Organization: University of Minnesota
  11. Lines: 70
  12. Nntp-Posting-Host: leghorn.cs.umn.edu
  13.  
  14. This has to be a FAQ, but here goes:
  15.  
  16. I want keyboard events from the main window of my application.  Sounds simple  
  17. enough, but I'm having problems.
  18.  
  19. I have a view with the following things overridden: keyDown and mouseDown.
  20.  
  21. First I tried the following:
  22.  
  23. #import <stdlib.h>
  24. #import <appkit/Application.h>
  25. #import "MyView.h"
  26.  
  27. void main(int argc, char *argv[]) {
  28.     id mv;
  29.  
  30.     NXApp = [Application new];
  31.     [NXApp loadNibSection:"t.nib" owner:NXApp];
  32.     mv = [[MyView alloc] init];
  33.     [[NXApp mainWindow] setContentView:mv];
  34.     [NXApp run];
  35.     [NXApp free];
  36.     exit(0);
  37. }
  38.  
  39. This doesn't get me the keyboard or mouse events.
  40.  
  41. Next I tried making my own window and then doing stuff with it:
  42.  
  43. #import <stdlib.h>
  44. #import <appkit/Application.h>
  45. #import <appkit/appkit.h>
  46. #import "MyView.h"
  47.  
  48. void main(int argc, char *argv[]) {
  49.     id mv;
  50.     id theWindow;
  51.     NXRect aRect;
  52.  
  53.     NXApp = [Application new];
  54.     [NXApp loadNibSection:"t.nib" owner:NXApp];
  55.  
  56.     NXSetRect(&aRect, 100.0, 350.0, 300.0, 300.0);
  57.     theWindow = [Window newContent:&aRect         /* create Window */
  58.                     style:NX_TITLEDSTYLE          /* object */
  59.                     backing:NX_BUFFERED
  60.                     buttonMask:NX_ALLBUTTONS
  61.                     defer:NO];
  62.     [theWindow setBackgroundGray:NX_WHITE];
  63.  
  64.     mv = [[MyView alloc] init];
  65.  
  66.     [theWindow setContentView: mv];
  67.  
  68.     [theWindow display];
  69.     [theWindow orderFront:nil];
  70.     [theWindow makeKeyWindow];
  71.  
  72.     [NXApp run];
  73.     [NXApp free];
  74.     exit(0);
  75. }
  76.  
  77. This was slightly more successful in that I now get the mouseDown events, but
  78. pressing a key just gives a miserable "boink."
  79.  
  80. Could anyone give me a clue to what's happening?
  81.  
  82. - Tim Rowley
  83.   rowley@leghorn.cs.umn.edu
  84.