|
¡û ¤Ï¤¸¤á¤Ë
LECTURE 9 ¤Î¥Þ¥¦¥¹Áàºî¤Ë´Ø¤¹¤ë¥¤¥Ù¥ó¥È¤Ë³¤¤¤Æ¡¢¤â¤¦ 1 ¤Ä¤Î½ÅÍפʥ桼¥¶ÆþÎϤǤ¢¤ë¥¡¼¥Ü¡¼¥ÉÁàºî¤Ë´Ø¤¹¤ë¥¤¥Ù¥ó¥È¤Ë¤Ä¤¤¤ÆÀâÌÀ¤·¤Þ¤¹¡£
¥¡¼¥Ü¡¼¥ÉÁàºî¤Ë´Ø¤¹¤ë¥¤¥Ù¥ó¥È¤Ë¤Ï¡¢¥æ¡¼¥¶¤¬¥¡¼¤ò²¡¤·¤¿¾ì¹ç( KeyPress ¥¤¥Ù¥ó¥È)¡¢Î¥¤·¤¿¾ì¹ç( KeyRelease ¥¤¥Ù¥ó¥È)¤Î 2 ¼ïÎब¤¢¤ê¤Þ¤¹¡£¤Þ¤¿¡¢¥¡¼¥¤¥Ù¥ó¥È¤½¤Î¤â¤Î¤Ç¤Ï¤¢¤ê¤Þ¤»¤ó¤¬´ØÏ¢¤¹¤ë¥¤¥Ù¥ó¥È¤È¤·¤Æ MappingNotify ¤È¤¤¤¦¥¤¥Ù¥ó¥È¤¬¤¢¤ê¤Þ¤¹¡£¤³¤³¤Ç¤Ï
¤Î½ç¤ËÀâÌÀ¤·¤Æ¤¤¤¤Þ¤¹¡£
¡û ¥¡¼¥¤¥Ù¥ó¥È
¥Ü¥¿¥ó¥¤¥Ù¥ó¥È¤Î»þ¤ÈƱÍͤˡ¢¥æ¡¼¥¶¤¬¥¡¼¤ò²¡¤·¤¿¾ì¹ç¤Ë¤Ï KeyPress ¥¤¥Ù¥ó¥È¤¬È¯À¸¤·¡¢Î¥¤·¤¿¾ì¹ç¤Ë¤Ï KeyRelease ¥¤¥Ù¥ó¥È¤¬È¯À¸¤·¤Þ¤¹¡£¤³¤ì¤é¤Î¥¤¥Ù¥ó¥È¤ò¥¡¼¥¤¥Ù¥ó¥È¤È¸Æ¤Ó¤Þ¤¹¡£¥¡¼¥¤¥Ù¥ó¥È¤Ë´Ø¤¹¤ë¾ðÊó¤ò³ÊǼ¤¹¤ë¤¿¤á¤Î¥¡¼¥¤¥Ù¥ó¥È¹½Â¤ÂΤò°Ê²¼¤Ë¼¨¤·¤Þ¤¹¡£
typedef struct { int type; /* ¥¤¥Ù¥ó¥È¤Î¼ïÎà */ unsigned long serial; /* ¥µ¡¼¥Ð¤¬½èÍý¤·¤¿ºÇ¸å¤Î¥ê¥¯¥¨¥¹¥È¤ÎÈÖ¹æ */ Bool send_event; /* ¥¯¥é¥¤¥¢¥ó¥È¤«¤éÁ÷¤é¤ì¤¿¥¤¥Ù¥ó¥È¤Ê¤éTrue */ Display* display; /* ¥¤¥Ù¥ó¥È¤¬Æɤ߹þ¤Þ¤ì¤¿display */ Window window; /* ¥¤¥Ù¥ó¥È¤¬È¯À¸¤·¤¿¥¦¥£¥ó¥É¥¦¤ÎID */ Window root; /* ¥¤¥Ù¥ó¥È¤¬µ¯¤³¤Ã¤¿¥¦¥£¥ó¥É¥¦¤ÎID */ Window subwindow; /* window¤Î»Ò¥¦¥£¥ó¥É¥¦ID */ Time time; /* ¥¤¥Ù¥ó¥ÈȯÀ¸»þ¹ï */ int x, y; /* ¥¤¥Ù¥ó¥È¤¬µ¯¤³¤Ã¤¿ºÂɸ(windowÆâ) */ int x_root, y_root; /* ¥¤¥Ù¥ó¥È¤¬µ¯¤³¤Ã¤¿ºÂɸ(rootÆâ) */ unsigned int state; /* ²¡¤µ¤ì¤Æ¤¤¤¿¥Ü¥¿¥ó¤ä½¤¾þ¥¡¼ */ unsigned int keycode; /* press¤¢¤ë¤¤¤Ïrelease¤µ¤ì¤¿¥¡¼¤Î¥³¡¼¥É */ Bool same_screen; /* ¥Þ¥¦¥¹¥«¡¼¥½¥ë¤¬window¤ÈƱ¥¹¥¯¥ê¡¼¥ó¤Ë¤¢¤ì¤ÐTrue */ } XKeyEvent; typedef XKeyEvent XKeyPressedEvent; typedef XKeyEvent XKeyReleasedEvent;
type ¤Ë¤Ï Äê¿ô KeyPress ¤« KeyRelease ¤Î¤¤¤º¤ì¤«¤¬Æþ¤ê¤Þ¤¹¡£x, y¤Ë¤Ï¥¤¥Ù¥ó¥È¤¬È¯À¸¤·¤¿¤È¤¤Î¥Þ¥¦¥¹¥«¡¼¥½¥ë¤Î°ÌÃÖºÂɸ¤¬Æþ¤ê¤Þ¤¹¡£
¥æ¡¼¥¶¤¬²¡¤·¤¿¤êÎ¥¤·¤¿¤ê¤·¤¿¥¡¼¤Î¾ðÊó¤È¤·¤Æ¡¢¥¡¼¥³¡¼¥ÉÈÖ¹æ( keycode )¤¬Á÷¤é¤ì¤ÆÍè¤Þ¤¹¡£¤³¤Î¥¡¼¥³¡¼¥ÉÈÖ¹æ¤Ï¥¡¼¤Ë°ì°Õ¤Ë³ä¤êÉÕ¤±¤é¤ì¤¿¥Ï¡¼¥É¥¦¥§¥¢°Í¸¤ÎÈÖ¹æ¤Ç¤¹¡£Ä̾ï¤Î¥×¥í¥°¥é¥à¤Ç¤Ï¡¢¤³¤Î¥¡¼¥³¡¼¥ÉÈÖ¹æ¤ò KeySym ̾¤ËÊÑ´¹¤·¤Æ KeySym ̾¤òÍѤ¤¤Þ¤¹¡£
¡û ¥ª¡¼¥È¥ê¥Ô¡¼¥È
X ¥µ¡¼¥Ð¤Î¥¡¼ÀßÄ꤬¥ª¡¼¥È¥ê¥Ô¡¼¥È¤Ë¤Ê¤Ã¤Æ¤¤¤ë¾ì¹ç¡¢¥ª¡¼¥È¥ê¥Ô¡¼¥ÈÃæ¤Î¥¡¼¤Ï KeyPress ¥¤¥Ù¥ó¥È¤È KeyRelease ¥¤¥Ù¥ó¥È¤¬¸ò¸ß¤ËÁ÷¤é¤ì¤ÆÍè¤Þ¤¹¡£¤³¤ÎÍͤʾì¹ç¤Ë¥¡¼¤ò²¡¤·¤Ã¤Ñ¤Ê¤·¤Ç¤¢¤ë¤ÈȽÄꤷ¤¿¤¤¾ì¹ç¤Ï¡¢¥ª¡¼¥È¥ê¥Ô¡¼¥È¤ò²ò½ü¤¹¤ëɬÍפ¬¤¢¤ë¤«¤â¤·¤ì¤Þ¤»¤ó¡£X ¥¯¥é¥¤¥¢¥ó¥È¤«¤é¥ª¡¼¥È¥ê¥Ô¡¼¥ÈÀßÄê¤òÁàºî¤¹¤ë¤Ë¤Ï¡¢°Ê²¼¤Î¤¤¤º¤ì¤«¤ò»ÈÍѤ·¤Þ¤¹¡£
- XAutoRepeatOn¡¿XAutoRepeatOff ¤ò»È¤¦
XAutoRepeatOn( Display* dpy ); XAutoRepeatOff( Display* dpy );
¤½¤ì¤¾¤ì¡¢Àܳ¤·¤¿ X ¥µ¡¼¥Ð¤Î¥¡¼¥Ü¡¼¥É¤Î¥ª¡¼¥È¥ê¥Ô¡¼¥È¤ò͸ú¡¿Ìµ¸ú¤Ë¤·¤Þ¤¹¡£ ¤³¤Î¾ì¹ç¡¢»ØÄꥡ¼¤Î¤ß¤Î¥ª¡¼¥È¥ê¥Ô¡¼¥ÈÀßÄê¤òÁàºî¤¹¤ë¤³¤È¤Ï½ÐÍè¤Þ¤»¤ó¡£
- XChangeKeyboardControl ¤ò»È¤¦
XChangeKeyboardControl( Display* dpy, unsigned long value_mask, XKeyboardControl* values ); value_mask : values ¤Î¤É¤Î¥á¥ó¥Ð¤¬Í¸ú¤ÊÀßÄêÃͤǤ¢¤ë¤«¤ò¥Þ¥¹¥¯»ØÄê values : value_mask ¤ËÀßÄꤵ¤ì¤Æ¤¤¤ë¥Þ¥¹¥¯¤ËÂбþ¤·¤¿¥á¥ó¥Ð¤Î»ØÄêÃͤòÀßÄê
¤³¤Î´Ø¿ô¤Ç¤Ï
- ¥¡¼¥¯¥ê¥Ã¥¯²»ÎÌ
- ¥Ù¥ë²»ÎÌ
- ¥Ù¥ë²»Ä´
- ¥Ù¥ëÌÄÆ°»þ´Ö
- LED ¾õÂÖ
- ¥ª¡¼¥È¥ê¥Ô¡¼¥È¾õÂÖ
¤òÀßÄꤹ¤ë¤³¤È¤¬½ÐÍè¤Þ¤¹¡£¤³¤³¤Ç¤Ï¥ª¡¼¥È¥ê¥Ô¡¼¥È¾õÂ֤ΤߤËÃíÌܤ·¤Þ¤¹¡£ ¥ª¡¼¥È¥ê¥Ô¡¼¥È¾õÂÖ¤ÎÀßÄê¤ËɬÍ×¤Ê XKeyboardControl ¤Î¥á¥ó¥Ð¤Ï int key ¤È int auto_repeat_mode ¤Ç¤¹¡£ key ¤È auto_repeat_mode ¤Î´Ø·¸¤Ï¡¢²¼É½¤ÎÄ̤ê¤Ç¤¹¡£
key auto_repeat_mode ¸ú²Ì ̤ÀßÄê ̤ÀßÄê ¸ú²Ì̵¤· ̤ÀßÄê ÀßÄê ¥¡¼¥Ü¡¼¥ÉÁ´ÂΤËÂФ¹¤ë¥ª¡¼¥È¥ê¥Ô¡¼¥ÈÀßÄê ÀßÄê ̤ÀßÄê BadMatch ÀßÄê ÀßÄê »ØÄꥡ¼¤ËÂФ¹¤ë¥ª¡¼¥È¥ê¥Ô¡¼¥ÈÀßÄê key ¤Ë¤Ï¶²¤é¤¯¥¡¼¥³¡¼¥É¤ò»ØÄꤹ¤ë¤Î¤À¤È»×¤¦¤Î¤Ç¤¹¤¬¡¢¼«Ê¬¤Ï¼ÂºÝ¤Ë¤Ï»È¤Ã¤¿¤³¤È¤¬Ìµ¤¤¤Î¤Ç̤Ĵºº¤Ç¤¹¡£¡£¡£¡Ê¤´¤á¤ó¤Ê¤µ¤¤¡Ëauto_repeat_mode ¤ËÀßÄê¤Ç¤¤ëÃͤϰʲ¼¤ÎÄ̤ê¤Ç¤¹¡£
Äê¿ô̾ ÀâÌÀ AutoRepeatModeOn ͸ú AutoRepeatModeOff ̵¸ú AutoRepeatModeDefault ¥Ç¥Õ¥©¥ë¥È¼ÂÁõ¤Ë½¾¤¦ valuemask ¤Ë¤Ï¡¢key ¤ò»ØÄꤹ¤ë¾ì¹ç¤Ë¤Ï KBKey¡¢auto_repeat_mode ¤Î¾ì¹ç¤Ï KBAutoRepeatMode ¤òÀßÄꤷ¤Þ¤¹ ( Î㡧valuemask = KBKey | KBAutoRepeatMode; )¡£
°Ê¾å¤Ï¥ª¡¼¥È¥ê¥Ô¡¼¥È¾õÂÖ¤òÀßÄꤹ¤ë¤¿¤á¤Î´Ø¿ô¤Ç¤¹¤¬¡¢¶²¤é¤¯Ä̾ï¤Ï¤³¤ì¤é¤ò¸Æ¤Ó½Ð¤¹Á°¤Î¾õÂÖ¤òÊݸ¤·¤Æ¤ª¤¤¤Æ¡¢ÉÔÍפˤʤä¿»þÅÀ¤Ç¸µ¤ÎÀßÄê¤ËÌᤷ¤¿¤¤¤À¤í¤¦¤È»×¤¤¤Þ¤¹¡£¸½ºß¤Î¥¡¼¥Ü¡¼¥É¤ÎÀ©¸æÃͤò¼èÆÀ¤¹¤ë¤Ë¤Ï¡¢XGetKeyboardControl ¤ò»È¤¤¤Þ¤¹¡£
XGetKeyboardControl( Display* dpy, XKeyboardState* values_return ); values_return : ¸½ºß¤ÎÀ©¸æÃÍ
XKeyboardState ¤Î¥á¥ó¥Ð¤Ç¡¢¥ª¡¼¥È¥ê¥Ô¡¼¥È¤Ë´Ø·¸¤¹¤ë¥á¥ó¥Ð¤Ï int global_auto_repeat ¤ª¤è¤Ó char auto_repeats[32] ¤Ç¤¹¡£global_auto_repeat ¤Ë¤ÏÁ°½Ò¤Î AutoRepeatModeOn ¤¢¤ë¤¤¤Ï AutoRepeatModeOff ¤¬³ÊǼ¤µ¤ì¤Þ¤¹¡£auto_repeats ¤Ë¤Ï¥¡¼¤ËÂбþ¤·¤¿¥Ó¥Ã¥È¤Ë¥ª¡¼¥È¥ê¥Ô¡¼¥ÈÀßÄ꤬³ÊǼ¤µ¤ì¤Þ¤¹¡£auto_repeats ¤Ë¤Ä¤¤¤Æ¤Ï¡¢¼«Ê¬¤Ï¼ÂºÝ¤Ë»È¤Ã¤¿¤³¤È¤¬Ìµ¤¤¤Î¤Ç̤Ĵºº¤Ç¤¹¡¢ºÆÅÙ¤´¤á¤ó¤Ê¤µ¤¤¡£
¡û ¥¡¼¥³¡¼¥É¤ÎÊÑ´¹
²¡¤µ¤ì¤¿(Î¥¤µ¤ì¤¿)¥¡¼¤Î¾ðÊó¤È¤·¤Æ X ¥µ¡¼¥Ð¤«¤éÁ÷¤é¤ì¤ÆÍè¤ë¤Î¤Ï¥¡¼¥³¡¼¥ÉÈÖ¹æ¤Ç¤¹¡£¥¡¼¥³¡¼¥ÉÈÖ¹æ¤Ï¥Ï¡¼¥É¥¦¥§¥¢¤Ë°Í¸¤·¤¿ÈÖ¹æ¤Ç¤¢¤ê¡¢¥á¡¼¥«¤Ë¤è¤Ã¤ÆÍÍ¡¹¤ÊÃͤȤʤê¤Þ¤¹¡£¤É¤Î¥¡¼¤¬²¡¤µ¤ì¤¿¤«¤ò¥×¥í¥°¥é¥àÆâ¤Ç½èÍý¤¹¤ë¾ì¹ç¤Ë¤Ï¡¢Ä̾ï¤Ï¥¡¼¥³¡¼¥ÉÈÖ¹æ¤ò X ¥¦¥£¥ó¥É¥¦¥·¥¹¥Æ¥à¤Ç°ì°Õ¤ËÄê¤á¤é¤ì¤Æ¤¤¤ë KeySym ̾¤ËÊÑ´¹¤·¤Æ½èÍý¤·¤Þ¤¹¡£
¥¡¼¥³¡¼¥ÉÈÖ¹æ¤ò KeySym ̾¤ËÊÑ´¹¤¹¤ë¤Ë¤Ï XLookupString() ¤ò»È¤¤¤Þ¤¹¡£
#include <Xutil.h> int XLookupString( XKeyEvent* event, char* buffer, int nbuffer, KeySym* keysym, XComposeStatus* status ); event : ¥¡¼¥Ü¡¼¥É¥¤¥Ù¥ó¥È buffer : ASCII¤ËÊÑ´¹¤·¤¿Ê¸»úÎó¤ò¤¤¤ì¤ë¥Ð¥Ã¥Õ¥¡ nbuffer : buffer¤Î¥µ¥¤¥º( ¥Ð¥¤¥È¿ô ) keysym : KeySym¤òÊÖ¤¹¡£¤¤¤é¤Ê¤¤¾ì¹ç¤Ï NULL¤ò»ØÄê status : ¥¡¼¹½À®¤Î¾õÂÖ¾ðÊ󡣤¤¤é¤Ê¤¤¾ì¹ç¤Ï NULL ¤ò»ØÄê
¤³¤Î´Ø¿ô¤Ï¡¢event ¤Ç»ØÄꤷ¤¿¥¡¼¥¤¥Ù¥ó¥È¾ðÊó¤ò»È¤Ã¤Æ KeySym ̾¤È ASCII ¤ËÊÑ´¹¤·¤Þ¤¹¡£´Ø¿ô¤ÎÊÖ¤êÃÍ¤Ï buffer ¤Ë³ÊǼ¤µ¤ì¤¿Ê¸»ú¿ô¤Ç¤¹¡£¥¡¼¥³¡¼¥ÉÈֹ椫¤é KeySym ̾¤Ø¤ÎÊÑ´¹¤Ï¡¢¥¡¼¥³¡¼¥É¤È KeySym ̾¤ÎÂбþɽ¤òÍѤ¤¤Æ¹Ô¤ï¤ì¤Þ¤¹¡£¤³¤ÎÂбþɽ¤Ï X ¥µ¡¼¥Ð¤È¤ÎÀܳ»þ¤Ë X ¥µ¡¼¥Ð¤«¤é¥³¥Ô¡¼¤µ¤ì¤Þ¤¹¡£
¼ç¤Ê KeySym ̾(ËͤÎÆÈÃǤÈÊ諤ÇÁª¤ó¤À KeySym ̾¤Ç¤¢¤Ã¤Æ¡¢Á´¤Æ¤Ç¤Ï¤¢¤ê¤Þ¤»¤ó)¤ò²¼É½¤Ë¼¨¤·¤Þ¤¹¡£Á´¤Æ¤Î KeySym ̾¤Ë¤Ä¤¤¤Æ¤Ï¡¢<X11/keysym.h> ¤ò»²¾È¤·¤Æ¤¯¤À¤µ¤¤¡£
KeySym ̾ | ¥¡¼ |
---|---|
XK_space | ¥¹¥Ú¡¼¥¹ |
XK_Escape | Esc |
XK_Control_L, R | CTRLº¸¡¢±¦ |
XK_Alt_L, R | ALTº¸¡¢±¦ |
XK_Delete | Del |
XK_Insert | Ins |
XK_Left | ¢« |
XK_Right | ¢ª |
XK_Up | ¢¬ |
XK_Down | ¢ |
XK_F1¡ÁXK_F10 | F1¡ÁF10 |
XK_exclam | ! |
XK_at | @ |
XK_0 ¡Á XK_9 | 0¡Á9 |
XK_A¡ÁXK_Z | A¡ÁZ |
XK_a¡ÁXK_z | a¡Áz |
¡û MappingNotify ¥¤¥Ù¥ó¥È
¥¡¼¥³¡¼¥É¤ÎÊÑ´¹¤Î½ê¤Ç¡¢¥¡¼¥³¡¼¥É¤È KeySym ̾¤ÎÂбþɽ¤ò X ¥µ¡¼¥Ð¤«¤é¥³¥Ô¡¼¤·¤Æ¤¯¤ë¤ÈÀâÌÀ¤·¤Þ¤·¤¿¡£¤È¤³¤í¤Ç¡¢¤³¤ÎÂбþɽ¤Ï¾ï¤Ë°ìÄê¤Ç¤Ï¤Ê¤¯¡¢X ¤Î¥¯¥é¥¤¥¢¥ó¥È¤Ç¤¢¤ë xmodmap ¤Ê¤É¤Ë¤è¤Ã¤Æ¥¡¼¥Ü¡¼¥É¤Î¥Þ¥Ã¥Ô¥ó¥°¤¬ÊѤ¨¤é¤ì¤ë¤³¤È¤¬¤¢¤ê¤Þ¤¹¡£¥Þ¥Ã¥Ô¥ó¥°¤¬ÊѤï¤Ã¤Æ¤·¤Þ¤¦¤È¡¢¥¡¼¥³¡¼¥É¤ò KeySym ̾¤ËÊÑ´¹¤·¤Æ»È¤Ã¤Æ¤¤¤ë¥×¥í¥°¥é¥à¤ÏÀµ¤·¤¯Æ°ºî¤·¤Ê¤¯¤Ê¤Ã¤Æ¤·¤Þ¤¦¤Î¤Ç¡¢¿·¤·¤¤Âбþɽ¤ò X ¥µ¡¼¥Ð¤«¤é¤â¤é¤Ã¤Æ¤³¤Ê¤±¤ì¤Ð¤Ê¤ê¤Þ¤»¤ó¡£
¤³¤Î¤è¤¦¤Ë¥¡¼¥Ü¡¼¥É¤Î¥Þ¥Ã¥Ô¥ó¥°¤¬ÊѤï¤Ã¤¿»þ¤Ë¤Ï¡¢X ¥µ¡¼¥Ð¤«¤é MappingNotify ¥¤¥Ù¥ó¥È¤¬Á÷¤é¤ì¤ÆÍè¤Þ¤¹¡£¤³¤Î¥¤¥Ù¥ó¥È¤Ï XSelectInput() ¤Ç»ØÄꤷ¤Ê¤¯¤Æ¤â̵¾ò·ï¤ËÁ´¤Æ¤Î¥¢¥×¥ê¥±¡¼¥·¥ç¥ó¤ËÁ÷¤é¤ì¤ÆÍè¤Þ¤¹(¤³¤Î¤è¤¦¤Ê¥¤¥Ù¥ó¥È¤ò¥Î¥ó¥Þ¥¹¥«¥Ö¥ë¥¤¥Ù¥ó¥È¤È¸Æ¤Ó¤Þ¤¹)¡£¤è¤Ã¤Æ¡¢MappingNotify ¥¤¥Ù¥ó¥È¤ò¼õ¤±¼è¤Ã¤¿¤é X ¥µ¡¼¥Ð¤ËÌ䤤¹ç¤ï¤»¤ÆºÇ¿·¤ÎÂбþɽ¤ò¤â¤é¤Ã¤Æ¤¯¤ë¤è¤¦¤Ë¥³¡¼¥Ç¥£¥ó¥°¤·¤Æ¤ª¤±¤ÐÎɤ¤¤È¤¤¤¦¤ï¤±¤Ç¤¹¡£
»ý¤Ã¤Æ¤¤¤ëÂбþɽ¤òºÇ¿·¤Ë¤¹¤ë¤Ë¤Ï¡¢XRefreshKeyboardMapping() ¤ò»È¤¤¤Þ¤¹¡£¤³¤Î´Ø¿ô¤ò¼Â¹Ô¤¹¤ë¤À¤±¤ÇºÇ¿·¤ÎÂбþɽ¤¬¥³¥Ô¡¼¤µ¤ì¤Þ¤¹¡£
switch ( event.type ) { case MappingNotify : XRefreshKeyboardMapping( &event ); break; }