#!/usr/bin/python # Created by Matteo Rattotti on 13/03/06. # Copyright (c) 2006 - 2007 Shiny Frog. All rights reserved. # Contact matteo.rattotti@shinyfrog.net for any problem # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License # as published by the Free Software Foundation; either version 2 # of the License, or any later version. # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. # Subclassing if NSAPP that handle global hotkey from AppKit import * from Foundation import * from PyObjCTools import NibClassBuilder, AppHelper from Carbon.CarbonEvt import RegisterEventHotKey, GetApplicationEventTarget from Carbon.Events import cmdKey, controlKey import struct kEventHotKeyPressedSubtype = 6 kEventHotKeyReleasedSubtype = 9 class NSAppSub (NSApplication): def finishLaunching(self): super(NSAppSub, self).finishLaunching() # register delibar global hotkey #hotk = NSUserDefaults.standardUserDefaults().objectForKey_("deliHotkey") #keycode = NSUserDefaults.standardUserDefaults().integerForKey_("deliKeyCode") #if hotk == None or hotk == "None" or hotk == "invalid key": # pass #else: # NSLog("registering "+ hotk +" hotkey") # self.hotKeyRef = RegisterEventHotKey(keycode, cmdKey | controlKey, (0, 0), # GetApplicationEventTarget(), 0) def sendEvent_(self, theEvent): # the event.keycode() -> return the keycode typed if theEvent.type() == NSSystemDefined and \ theEvent.subtype() == kEventHotKeyPressedSubtype: self.activateIgnoringOtherApps_(True) self.delegate().hotKeyRespond_() super(NSAppSub, self).sendEvent_(theEvent)