SetHHK InXUsing Hotplug
Hotplug¸¦ ÀÌ¿ëÇؼ HappyHacking Keyboard Å°¸Ê ÁöÁ¤Çϱ⠶ÀÌ ±ÛÀº ¸®´ª½ºÀÇ Hotplug ±â´ÉÀ» ÀÌ¿ëÇؼ X Window¿¡¼ »ç¿ëÀÚ°¡ ÁöÁ¤ÇÑ Å°¸Ê, Xmodmap ¼³Á¤ÆÄÀÏ,ÇØÇÇÇØÅ· Å°º¸µåÀÇ Å°¸ÊÀ» Àû¿ë½ÃÅ°´Â ¹æ¹ýÀ» ¼³¸íÇÕ´Ï´Ù. Á¦°¡ »ç¿ëÇÏ´Â µ¥ºñ¾È ½Ãµå Debian Sid¸¦ ±âÁØÀ¸·Î ¼³¸íÇÕ´Ï´Ù.
Àú´Â Thinkpad T42 ³ëÆ®ºÏ¿¡ HHK¸¦ »ç¿ëÇÏ°í ÀÖ½À´Ï´Ù. HHKÀÇ ¿ø·¡ Å°¸Ê¿¡ Àͼ÷ÇØÁöÁú ¾Ê¾Æ¼ ºÎµæÀÌ tilde(~)Å°¿Í EscÅ°¸¦ ¾Æ¿¹ ŰĸÀ» ¹Ù²ã³¢¿ì°í, Caps_Lock ÀÚ¸®¿¡ ÀÖ´Â HHKÀÇ ControlÅ°¸¦ EscapeÅ°·Î ¹èÁ¤Çؼ »ç¿ëÇÏ°í ÀÖ½À´Ï´Ù. AltÅ°¿Í ±× ¿·ÀÇ »ç°¢ÇüÅ°µµ ¹Ù²ã¼ ´Ù¸¥ Å°º¸µåµéó·³ Control, Alt ¼ø¼·Î ¹èÁ¤Çؼ »ç¿ëÇÏ°í ÀÖ½À´Ï´Ù. HHK¸¦ ºÙÀÏ ¶§¸¶´Ù º¯°æµÈ Å°¸ÊÀ» ¼³Á¤ÇϱⰡ ¹ø°Å·Î¿ö¼ Hotplug¸¦ ÀÌ¿ëÇؼ ÀÚµ¿À¸·Î Àνĵǵµ·Ï ¼³Á¤ÇغýÀ´Ï´Ù.
(¾Æ·¡¿¡ ¼³¸íÇÏ´Â ¹æ¹ýÀÌ hotplug¸¦ Á¦´ë·Î »ç¿ëÇÏ´Â °ÍÀÎÁö Àß ¸ð¸£°Ú³×¿ä. º¸ÃæÇØ¾ß µÉ ºÎºÐÀº ÁöÀûÇØÁÖ¼¼¿ä.)
Hotplug¿¡ ´ëÇÑ ±¸Ã¼ÀûÀÎ ¼³¸íÀº LinuxHotplug ÆäÀÌÁö¸¦ Âü°íÇϼ¼¿ä.
2. ¸ÕÀú, ¶
3. ½ºÅ©¸³Æ®¸¦ ÀÛ¼ºÇÕ´Ï´Ù. ¶/etc/hotplug_device.d µð·ºÅ丮¸¦ ¸¸µì´Ï´Ù.
shell > mkdir /etc/hotplug_device.d ´ÙÀ½ ½ºÅ©¸³Æ®¸¦ ÀÛ¼ºÇÕ´Ï´Ù.
/etc/hotplug.d/usb/usbhid.hotplug
#!/usr/bin/env python
import os, glob, sys, sre DIR_HOTPLUG_DEVICE = "/etc/hotplug_device.d" if not os.path.isdir(DIR_HOTPLUG_DEVICE) : sys.exit(1) sys.path.append(DIR_HOTPLUG_DEVICE) for i in glob.glob("%s/*_usb.py" % DIR_HOTPLUG_DEVICE) : __device_filename = sre.compile(".py$").sub("", os.path.basename(i)) __module = __import__(__device_filename, globals(), locals(), [__device_filename,]) DEVICE = getattr(__module, "device") DEVICE().do() /etc/hotplug_device.d/BASIC_USB.py
import os, sys, pickle
class device : LOG_HOTPLUG_DEVICE = "/var/run/hotplug_device.pkl" ACTION = "" DEVPATH_REMOVE = "" DEVPATH = "" PRODUCT = "" MANUFACTURER = "" def __init__ (self) : self.get_info() def get_info (self) : self.ACTION = os.getenv("ACTION") self.DEVPATH = "/sys%s" % os.getenv("DEVPATH") self.DEVPATH_REMOVE = os.sep.join(self.DEVPATH.split(os.sep)[:-2]) if not os.path.isdir(self.DEVPATH) : raise RuntimeError, "devpath, %s does not exists" % self.DEVPATH # get PRODUCT name and get MANUFACTURER name __file_product = "%s/product" % os.sep.join(self.DEVPATH.split(os.sep)[:-1]) __file_manufacture = "%s/manufacturer" % os.sep.join(self.DEVPATH.split(os.sep)[:-1]) if os.path.isfile(__file_product) : self.PRODUCT = "".join(open(__file_product, "r").readlines()).strip() if os.path.isfile(__file_manufacture) : self.MANUFACTURER = "".join(open(__file_manufacture, "r").readlines()).strip() def check_add (self) : pass def check_remove (self) : pass def do (self) : data = self.get_data() if self.ACTION == "add" : if self.check_add() : self.add() data[self.DEVPATH_REMOVE] = \ (self.PRODUCT, self.MANUFACTURER, self.ACTION,) self.store_data(data) return True elif self.ACTION == "remove" : if self.check_remove() : self.remove() del(data[self.DEVPATH]) self.store_data() return True return False def add (self) : self.store_data() def remove (self) : pass def store_data (self, data) : """ store information for removing this devices. """ __fd_pk = open(self.LOG_HOTPLUG_DEVICE, "w") pickle.dump(data, __fd_pk) __fd_pk.close() def get_data (self) : if not os.path.isfile(self.LOG_HOTPLUG_DEVICE) : __data = dict() else : __fd_pk = open(self.LOG_HOTPLUG_DEVICE, "r") try : __data = pickle.load(__fd_pk) except : __data = dict() return __data def run_external_command (self, cmd) : pi, po, pe = os.popen3(cmd) return (pi, po, pe,) /etc/hotplug_device.d/HHK_usb.py
import os, sys, pickle
import __BASIC_USB__ XMODMAP = "/usr/bin/X11/xmodmap" MAPFILE_BASIC = "/usr/local/etc/xmodmap/basic" MAPFILE_HHK = "/usr/local/etc/xmodmap/HHK" MAPFILE_TP = "/usr/local/etc/xmodmap/TP" class device (__BASIC_USB__.device) : KEY_PRODUCT = "PFU-65 USB Keyboard" KEY_MANUFACTURER = "Chicony" def check_add (self) : # if this attached device is keyboard and is HHK. if not self.PRODUCT == self.KEY_PRODUCT or \ not self.MANUFACTURER == self.KEY_MANUFACTURER : return False return True def check_remove (self) : if not os.path.isfile(self.LOG_HOTPLUG_DEVICE) : return False __data = self.get_data() return self.DEVPATH in __data def add (self) : self.xmodmap(MAPFILE_BASIC) self.xmodmap(MAPFILE_HHK) def remove (self) : self.xmodmap(MAPFILE_BASIC) self.xmodmap(MAPFILE_TP) def xmodmap (self, mapfile) : self.run_external_command("/bin/su spike -c '%s -display :0.0 %s'" % (XMODMAP, mapfile)) À§¿¡¼
MAPFILE_BASIC = "/usr/local/etc/xmodmap/basic"
MAPFILE_HHK = "/usr/local/etc/xmodmap/HHK" MAPFILE_TP = "/usr/local/etc/xmodmap/TP" ±×¸®°í /etc/hotplug_device.d/HHK_usb.pyÀÇ ¸¶Áö¸· ºÎºÐ
def xmodmap (self, mapfile) :
self.run_external_command("/bin/su spike -c '%s -display :0.0 %s'" % (XMODMAP, mapfile)) ¸¶Áö¸·À¸·Î
shell > chmod 700 /etc/hotplug.d/usb/usbhid.hotplug 4. Å×½ºÆ®, ¶À§ÀÇ ½ºÅ©¸³Æ®¸¦ ¸ðµÎ Á¦ À§Ä¡¿¡ °®´Ù³õ°í, ÀÌÁ¦ ½ÃÇèÀ» Çغ¾´Ï´Ù. HHK¸¦ usb¿¡ ºÙÀÌ°í »©°í¸¦ ¹Ýº¹ÇÏ¸é¼ ¿øÇÏ´Â Å°¸ÊÀÌ Á¦´ë·Î ÁöÁ¤µÇ´ÂÁö Å×½ºÆ®Çغ¾´Ï´Ù. ½ºÅ©¸³Æ®¸¦ µð¹ö±ëÇϱⰡ ¸¶¶àÄ¡ ¾Ê±ä ÇÏÁö¸¸, ¹®Á¦°¡ µÉ ¸¸ÇÑ ºÎºÐÀ» Á¶±Ý¾¿ ¼öÁ¤ÇØ°¡¸é¼ Å×½ºÆ®Çغ¾´Ï´Ù.
5. ÆÄÀÏµé ¶usbhid.hotplug.gz (392 Bytes)
HHK_usb.py.gz (492 Bytes)
attachment:BASIC_USB.py.gz
HHK.gz (210 Bytes)
TP.gz (163 Bytes)
basic.gz (56 Bytes)
|
It is better to wear out than to rust out. |