📄 awaitevent.c
字号:
#include <phigs.h> /* get HP-PHIGS definitions for C */#include <stdio.h> /* get standard I/O definitions */#include <math.h> /* link with library "-lm" */main() /* file "AwaitEvent.c" */{ Pint WorkstnID = 1; /* workstation identifier */ Pint ConnID; /* connection identifier */ Pint WorkstnType = POIDDX; /* out/in, direct, dbl bfr, Xwindow */ Pint Mouse = 1; /* \ */ Pint KeyBoard = 2; /* > supported choice devices */ Pint FunctionKeys = 3; /* / */ Pint RtnDevice; /* returned device */ Pint RtnClass; /* returned class */ Pint RtnWorkstnID; /* returned workstation ID */ Pint Error; /* error indicator */ Pfloat TimeOut = 60; /* timeout value for await event */ Pmore_simult_events Simultaneous; /* more simultaneous events? */ popen_phigs((char *) stderr, 0); /* errors go to "stderr" */ pescape_u4("/dev/screen/phigs_window", &ConnID); popen_ws(WorkstnID, (void *) ConnID, WorkstnType); pset_choice_mode(WorkstnID, Mouse, POP_EVENT, PSWITCH_ECHO); pset_loc_mode (WorkstnID, Mouse, POP_EVENT, PSWITCH_ECHO); pset_choice_mode(WorkstnID, FunctionKeys, POP_EVENT, PSWITCH_ECHO); pset_choice_mode(WorkstnID, KeyBoard, POP_EVENT, PSWITCH_ECHO); printf("Ready. (Type 'Q' or click in the lower-left corner to quit.)\n"); while (1) { pawait_event(TimeOut, &RtnWorkstnID, &RtnClass, &RtnDevice); if (RtnClass == PIN_NONE) { printf("One-minute timeout occurred; terminating.\n"); break; } else GetInfo(RtnClass, RtnDevice); pinq_more_simult_events(&Error, &Simultaneous); if (Error) printf("Error %d returned from \"pinq_more_simult_events\".\n", Error); while (Simultaneous == PSIMULT_MORE) { printf("Simultaneous event: "); pawait_event(TimeOut, &RtnWorkstnID, &RtnClass, &RtnDevice); GetInfo(RtnClass, RtnDevice); pinq_more_simult_events(&Error, &Simultaneous); } } pclose_ws(WorkstnID); pclose_phigs();}/****************************************************************************/GetInfo(DevClass, DevNumber)Pint DevClass, DevNumber; /* device class, number */{ Pint Status, Choice; /* returned choice status, number */ Pint ViewIndex; /* returned viewindex from locator */ Ppoint3 Location; /* returned XYZ location */ if (DevClass == PIN_CHOICE) { pget_choice(&Status, &Choice); if (Status == PIN_STATUS_OK) { if (DevNumber == 1) printf("Mouse button: %d\n", Choice); if (DevNumber == 2) { printf("Keyboard key: '%c' (%d)\n", Choice > ' ' && Choice <= '~'? Choice:' ', Choice); if (Choice == 'Q') { printf("'Q' typed; quitting.\n"); exit(0); } } if (DevNumber == 3) printf("Function key: %d\n", Choice); } else printf("(No choice input)\n"); } if (DevClass == PIN_LOC) { pget_loc3(&ViewIndex, &Location); printf("Locator: (%4.2f, %4.2f, %4.2f); View index=%d.\n", Location.x, Location.y, Location.z, ViewIndex); if (Location.x < 0.1 && Location.y < 0.1) { printf("Mouse clicked in lower-left corner; quitting.\n"); exit(0); } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -