Code Viewer

./Classes/__hotkey.js File Size: 14.02 KB

  1. /*
  2. * -----
  3. * Screenshot Sender - __hotkey.js
  4. * -----
  5. * Hotkey functions for Screenshot Sender 5
  6. * -----
  7. */
  8.  
  9. var Hotkeys = function () {
  10.         this.WM_HOTKEY = 0x312;
  11.         this.HK_SETKEY = 0x401;
  12.         this.HK_GETKEY = 0x402;
  13.         this.MOD_WIN = 0x8;
  14.         this.MOD_ALT = 0x1;
  15.         this.MOD_CONTROL = 0x2;
  16.         this.MOD_SHIFT = 0x4;
  17.  
  18.         //Subclass window information
  19.         GlobalHotkey.Subclass.Registry.GetValue = function () {
  20.                 Registry_GetKeyValue(HKCU, RegistryInit(), 'SubclassHandle');
  21.         };
  22.         GlobalHotkey.Subclass.Registry.SetValue = function (hWndSubclass) {
  23.                 Registry_SetKeyValue(HKCU, RegistryInit(), 'SubclassHandle', hWndSubclass, REG_DWORD);
  24.         };
  25.         //Actions
  26.         GlobalHotkey.Actions.Add("BeforeRegister", function () {
  27.                 _debug.trace("> Start registering hotkeys");
  28.         });
  29.         GlobalHotkey.Actions.Add("RegisterHotkey", function (oHotkey, bSuccess) {
  30.                 _debug.trace("   '"+oHotkey.Id+"' -> '"+oHotkey.KeyName+"' ..."+ (bSuccess?"Success!":"Error!") );
  31.         });
  32.         GlobalHotkey.Actions.Add("AfterRegister", function (bSuccess, aFailed) {
  33.                 _debug.trace("> Global hotkeys registration "+ (bSuccess?"succesfully completed":"failed!") );
  34.                 if (!bSuccess) _debug.trace("  "+ (aFailed ? aFailed.length : 0) +" hotkey(s) failed to register");
  35.         });
  36. }
  37.  
  38. Hotkeys.prototype = {
  39.         "Initialize" : function () {
  40.                 // Don't do anything when already initialized
  41.                 if (GlobalHotkey.IsInit() ) return;
  42.                 // If the file exists in the current translation, load it
  43.                 var Name = 'Hotkey_Subclass';
  44.                 var FilePath = InterfacePath + (typeof objPreferences['cLanguage']  === 'undefined' ? MsgPlus.UILangCode : objPreferences['cLanguage']) + '\\' + Name + '.xml';
  45.                 if (FileExists(FilePath) == false) {
  46.                         // Otherwise, load the default translation(en)
  47.                         FilePath = InterfacePath + 'en\\' + Name + '.xml';
  48.                 }
  49.                 // Set the hotkey subclass details
  50.                 GlobalHotkey.Subclass.InterfacePath = '\\' + FilePath;
  51.                 GlobalHotkey.Subclass.WindowId = Name;
  52.                 // Initialize the class
  53.                 GlobalHotkey.Init();
  54.         },
  55.        
  56.         "LoadHotkeys" : function () {
  57.                 // Delete all registered hotkeys
  58.                 GlobalHotkey.DeleteAll();
  59.                 // Collect the hotkeys from the registry
  60.                 var objSubkeys = {};
  61.                 Registry_EnumSubkeys(HKCU, RegistryInit() +'\\Hotkeys\\', objSubkeys);
  62.                 for (var objSubkey in objSubkeys) {
  63.                         if (Registry_GetKeyValue(HKCU, RegistryInit() +'\\Hotkeys\\'+objSubkey, 'bEnabled') === 1) {
  64.                                 var lKeyCode = Registry_GetKeyValue(HKCU, RegistryInit() +'\\Hotkeys\\'+objSubkey, 'Hotkey');
  65.                                 var lAction = Registry_GetKeyValue(HKCU, RegistryInit() +'\\Hotkeys\\'+objSubkey, 'Action');
  66.                                 var fCallback = this.GetHotkeyCallback(lAction);
  67.                                 GlobalHotkey.Add(Messenger.MyUserId+':'+lKeyCode, lKeyCode, 0, fCallback);
  68.                         }
  69.                 }
  70.                 // Reload the hotkeys
  71.                 GlobalHotkey.Reload();
  72.         },
  73.        
  74.         "GetHotkeyCallback" : function (lAction) {
  75.                 return this.BindFunction (function (oHotkey) {
  76.                         _debug.trace("Hotkey "+oHotkey.KeyName+" pressed - lAction = "+lAction);
  77.                         this.ProcessHotkeyAction(lAction);
  78.                 }, this);
  79.         },
  80.        
  81.         "PauseHotkeyHandling" : function (bPaused) {
  82.                 GlobalHotkey.Break(bPaused);
  83.         },
  84.        
  85.         "UnregisterHotkeys" : function (hWnd) {
  86.                 GlobalHotkey.DeleteAll();
  87.                 GlobalHotkey.Destroy();
  88.         },
  89.        
  90.         "GetKeyName" : function (uCode) {
  91.                 return GlobalHotkey.GetKeyName(uCode);
  92.         },
  93.        
  94.         "ProcessHotkeyMessage" : function (pPlusWnd, nMessage, wParam, lParam) {
  95.                 return GlobalHotkey.HandleNotification(arguments);
  96.         },
  97.        
  98.         "ProcessHotkeyAction" : function (lAction, bPrntScrn) {
  99.                 if (typeof bPrntScrn  === 'undefined') bPrntScrn = false;
  100.                 var oGdip = new Gdip();
  101.                 oGdip.Initialize();
  102.                 var bSave; // set to true if the hotkey is for saving the image false if its for sending
  103.                 var bDelay = false; // used to check if the hotkey causes a delay such as select area
  104.                 switch (lAction) {
  105.                         case 0: oGdip.SaveImage(oGdip.CaptureWindow_Active(), SessionImages.CreateTempImage() ); bSave = false; break;
  106.                         case 1: oGdip.SaveImage(oGdip.CaptureWindow_Active(), SessionImages.CreateTempImage() ); bSave = true; break;
  107.                         case 2: oGdip.SaveImage(oGdip.CaptureWindow_Fullscreen(), SessionImages.CreateTempImage() ); bSave = false; break;
  108.                         case 3: oGdip.SaveImage(oGdip.CaptureWindow_Fullscreen(), SessionImages.CreateTempImage() ); bSave = true; break;
  109.                         case 4: oGdip.SaveImage(oGdip.CaptureWindow_Clipboard(), SessionImages.CreateTempImage() ); bSave = false; break;
  110.                         case 5: oGdip.SaveImage(oGdip.CaptureWindow_Clipboard(), SessionImages.CreateTempImage() ); bSave = true; break;
  111.                         case 6: SelectedArea(0, 'ssselect', 0, false); bSave = false; bDelay = true; break;
  112.                         case 7: SelectedArea(0, 'sssselect', 0, true); bSave = true;    bDelay = true; break;
  113.                         case 8: PointClickCapture(0, 'sspcc', 0, false); bSave = false; bDelay = true; break;
  114.                         case 9: PointClickCapture(0, 'ssspcc', 0, true); bSave = true;  bDelay = true; break;
  115.                         default: oGdip.Uninitialize(); return false;
  116.                 }
  117.                 if (bDelay == false && objPreferences['cPreviews'] == true) Preview(0, oGdip.ImageLocation, bSave);
  118.                 if (bPrntScrn == true) oGdip.Clipboard_SetData(oGdip.hBitmap);
  119.                 oGdip.Uninitialize();
  120.         },
  121.        
  122.         "LoadConfiguredHotkeys" : function (pPlusWnd, sControlId) {
  123.                 var objSubkeys = {}, nIndex = 0;
  124.                 Registry_EnumSubkeys(HKCU, RegistryInit() +'\\Hotkeys\\', objSubkeys);
  125.                 for (var objSubkey in objSubkeys) {
  126.                         var bEnabled = Registry_GetKeyValue(HKCU, RegistryInit() +'\\Hotkeys\\'+objSubkey, 'bEnabled');
  127.                         nIndex = pPlusWnd.LstView_AddItem(sControlId, _lang.text['HotkeyActions_'+Registry_GetKeyValue(HKCU, RegistryInit() +'\\Hotkeys\\'+objSubkey, 'Action')]);
  128.                         pPlusWnd.LstView_SetItemText(sControlId, nIndex, 1, this.GetKeyName(Registry_GetKeyValue(HKCU, RegistryInit() +'\\Hotkeys\\'+objSubkey, 'Hotkey') ) );
  129.                         pPlusWnd.LstView_SetItemText(sControlId, nIndex, 2, objSubkey);
  130.                         pPlusWnd.LstView_SetItemText(sControlId, nIndex, 3, bEnabled);
  131.                         pPlusWnd.LstView_SetItemIcon(sControlId, nIndex, bEnabled, true);
  132.                 }
  133.         },
  134.        
  135.         "AddAtom" : function (_string) { return Interop.Call('kernel32', 'GlobalAddAtomW', _string); },
  136.        
  137.         "GetAtom" : function (_string) { return Interop.Call('kernel32', 'GlobalFindAtomW', _string); },
  138.        
  139.         "GetAtomName" : function (_atom) { var _sBuffer = Interop.Allocate(512); Interop.Call('kernel32', 'GlobalGetAtomNameW', _atom, _sBuffer, 512); return _sBuffer.ReadString(0); },
  140.        
  141.         "DeleteAtom" : function (_atom) { Interop.Call('kernel32', 'GlobalDeleteAtom', _atom.toString(16) ); },
  142.        
  143.         "lobyte" : function (w) { return w & 0xff; },
  144.        
  145.         "hibyte" : function (w) { return w >> 8; },
  146.        
  147.         "makeword" : function (a,b) { return a | (b << 8); },
  148.        
  149.         //Binds a function to an object - based on Function.bind from Prototype(www.prototypejs.org)
  150.         "BindFunction" : function () {
  151.                 var args = toArray(arguments);
  152.                 var func = args.shift();
  153.                 var obj = args.shift();
  154.                 return function () {
  155.                         return func.apply(obj, args.concat(toArray(arguments) ) );
  156.                 }
  157.                
  158.                 function toArray(iterable) {
  159.                         if (!iterable) return[];
  160.                         if (iterable.toArray) return iterable.toArray();
  161.                         var length = iterable.length, results = new Array(length);
  162.                         while (length--) results[length] = iterable[length];
  163.                         return results;
  164.                 }
  165.         }
  166. }

Version

  • 5.0.0070_20100325_publicbeta1

Developers

Project Details

  • Folders8
  • Files122
  • Total Lines11,867
  • Repository Version70

User Count

  • 162