1 /**************************************
3 * Written by Timm Martin
4 * This source code is public domain.
5 ***************************************/
7 #include <aros/oldprograms.h>
9 #include <exec/types.h>
10 #include <intuition/intuition.h>
11 #include <intuition/intuitionbase.h>
17 *********************/
19 struct IntuitionBase
*IntuitionBase
= NULL
;
20 struct Window
*win
= NULL
;
22 /************************
23 * NEW WINDOW STRUCTURE
24 *************************/
26 struct NewWindow new_window
=
28 /* SHORT LeftEdge */ 0,
29 /* SHORT TopEdge */ 0,
30 /* SHORT Width */ 640,
31 /* SHORT Height */ 40,
32 /* UBYTE DetailPen */ 0,
33 /* UBYTE BlockPen */ 1,
34 /* ULONG IDCMPFlags */ CLOSEWINDOW
|RAWKEY
,
35 /* ULONG Flags */ ACTIVATE
|NOCAREREFRESH
|SIMPLE_REFRESH
|WINDOWCLOSE
|WINDOWDEPTH
|WINDOWDRAG
|WINDOWSIZING
,
36 /* struct Gadget * FirstGadget */ NULL
,
37 /* struct Image * CheckMark */ NULL
,
38 /* UBYTE * Title */ (STRPTR
)"Input Test Program",
39 /* struct Screen * Screen */ NULL
,
40 /* struct BitMap * BitMap */ NULL
,
41 /* SHORT MinWidth */ 230,
42 /* SHORT MinHeight */ 20,
43 /* USHORT MaxWidth */ 640,
44 /* USHORT MaxHeight */ 200,
45 /* USHORT Type */ WBENCHSCREEN
,
52 int main( int argc
, char *argv
[] );
53 void print_key( USHORT key
);
54 void program_end( char *error
);
55 void program_begin( void );
56 void window_input( void );
62 int main( int argc
, char *argv
[] )
64 /* quit if not run from the CLI -- nowhere to send output */
79 This procedure opens the Intuition library, the window, and the console
80 device. If any of these things fail, the program ends.
83 void program_begin( void )
85 if (!(IntuitionBase
= (struct IntuitionBase
*)
86 OpenLibrary( "intuition.library", 0L )))
87 program_end( "intuition" );
89 if (!(win
= OpenWindow( &new_window
)))
90 program_end( "window" );
93 program_end( "console" );
101 This procedure closes the console device, the window, and the Intuition
102 library. It also prints an error message (if any) to the CLI.
105 void program_end( char *error
)
107 if (error
) printf( "FAILED: %s\n", error
);
111 if (win
) CloseWindow( win
);
112 if (IntuitionBase
) CloseLibrary((struct Library
*) IntuitionBase
);
120 This procedure monitors for window input. It returns when the user clicks on
121 the window close gadget.
124 void window_input( void )
127 struct IntuiMessage
*imessage
;
133 /* wait for input from the window */
134 Wait( 1L<<win
->UserPort
->mp_SigBit
);
136 /* for each input message */
137 while ((imessage
= (struct IntuiMessage
*)GetMsg( win
->UserPort
)))
139 switch (imessage
->Class
)
142 finished
= TRUE
; /* end the program */
145 if ((key
= input_key( imessage
))) /* if a key was pressed */
146 print_key( key
); /* print it */
149 /* reply to the message to free its memory */
150 ReplyMsg( (struct Message
*)imessage
);
160 This procedure prints an English description of the key that was pressed and
164 char *command_keys
[] =
166 NULL
, "F1", "F2", "F3", "F4", "F5", "F6", "F7", "F8", "F9", "F10", "TAB",
167 "DELETE", "ESCAPE", "BACKSPACE", "HELP", "RETURN", "UP_ARROW",
168 "DOWN_ARROW", "LEFT_ARROW", "RIGHT_ARROW",
171 void print_key( USHORT key
)
175 /* check for qualifiers */
176 if (key
& QUAL_LSHIFT
)
178 if (key
& QUAL_RSHIFT
)
180 if (key
& QUAL_CONTROL
)
181 printf( "CONTROL " );
186 if (key
& QUAL_LAMIGA
)
188 if (key
& QUAL_RAMIGA
)
191 /* which key was pressed? */
192 c
= KEY_VALUE( key
);
194 /* if this was a command key */
195 if (KEY_COMMAND( key
))
196 printf( "%s\n", command_keys
[c
] );
197 /* else just normal ASCII character */
199 printf( "'%c'\n", c
);