| 1 | import clr |
|---|
| 2 | |
|---|
| 3 | from System import * |
|---|
| 4 | from System.Diagnostics import Process |
|---|
| 5 | from System.Runtime.InteropServices import Marshal |
|---|
| 6 | from System.Windows.Forms import * |
|---|
| 7 | from Misuzilla.Applications.AppleWirelessKeyboardHelper import Program, Util |
|---|
| 8 | |
|---|
| 9 | # Master Volume Control |
|---|
| 10 | clr.AddReferenceByPartialName("MasterVolumeControlLibrary") |
|---|
| 11 | from MasterVolumeControlLibrary import MasterVolumeControl |
|---|
| 12 | volControl = MasterVolumeControl.GetControl() |
|---|
| 13 | |
|---|
| 14 | def OnLoad(sender, e): |
|---|
| 15 | pass |
|---|
| 16 | |
|---|
| 17 | def OnUnload(sender, e): |
|---|
| 18 | volControl.Dispose() |
|---|
| 19 | |
|---|
| 20 | Program.Load += OnLoad |
|---|
| 21 | Program.Unload += OnUnload |
|---|
| 22 | |
|---|
| 23 | """ |
|---|
| 24 | Power Button |
|---|
| 25 | """ |
|---|
| 26 | def OnDown_Power(): |
|---|
| 27 | # Lock desktop |
|---|
| 28 | Process.Start("rundll32.exe", "user32.dll,LockWorkStation") |
|---|
| 29 | |
|---|
| 30 | """ |
|---|
| 31 | Eject Button |
|---|
| 32 | """ |
|---|
| 33 | def OnDown_Eject(): |
|---|
| 34 | #Util.Eject("E"); |
|---|
| 35 | pass |
|---|
| 36 | |
|---|
| 37 | """ |
|---|
| 38 | Alpha Numeric(eisu) (JIS only) |
|---|
| 39 | """ |
|---|
| 40 | def OnUp_JISAlphaNumeric(): |
|---|
| 41 | Util.SendInput(Keys.HanjaMode) # IME on/off |
|---|
| 42 | |
|---|
| 43 | """ |
|---|
| 44 | Kana Key (JIS only) |
|---|
| 45 | """ |
|---|
| 46 | def OnUp_JISKana(): |
|---|
| 47 | Util.SendInput(Keys.IMEConvert) # IME Convert |
|---|
| 48 | |
|---|
| 49 | """ |
|---|
| 50 | Fn + F1 ... F12 (OnDown_Fn_[KeyName]) |
|---|
| 51 | """ |
|---|
| 52 | def OnDown_Fn_F1(): |
|---|
| 53 | MessageBox.Show('Fn+F1') # System.Windows.Forms.MessageBox |
|---|
| 54 | |
|---|
| 55 | def OnDown_Fn_F2(): |
|---|
| 56 | Program.ShowBalloonTip('Fn+F2') # ShowBalloonTip(str) or ShowBalloonTip(str, System.Windows.Forms.ToolTipIcon) |
|---|
| 57 | |
|---|
| 58 | def OnDown_Fn_F3(): |
|---|
| 59 | if Environment.OSVersion.Version.Major >= 6: |
|---|
| 60 | Process.Start("rundll32.exe", "DwmApi #105") # 3D Filp |
|---|
| 61 | else: |
|---|
| 62 | toggleDesktop() # Show Desktops |
|---|
| 63 | |
|---|
| 64 | def OnDown_Fn_F4(): |
|---|
| 65 | Util.SendInput(Keys.PrintScreen) # System.Windows.Forms.Keys |
|---|
| 66 | |
|---|
| 67 | def OnDown_Fn_F5(): |
|---|
| 68 | pass |
|---|
| 69 | |
|---|
| 70 | def OnDown_Fn_F6(): |
|---|
| 71 | pass |
|---|
| 72 | |
|---|
| 73 | def OnDown_Fn_F7(): |
|---|
| 74 | # iTunes / Previous Track |
|---|
| 75 | execiTunes(lambda it: it.PreviousTrack()) |
|---|
| 76 | |
|---|
| 77 | def OnDown_Fn_F8(): |
|---|
| 78 | # iTunes / PlayPause |
|---|
| 79 | execiTunes(lambda it: it.PlayPause()) |
|---|
| 80 | |
|---|
| 81 | def OnDown_Fn_F9(): |
|---|
| 82 | # iTunes / PlayPause |
|---|
| 83 | execiTunes(lambda it: it.NextTrack()) |
|---|
| 84 | |
|---|
| 85 | def OnDown_Fn_F10(): |
|---|
| 86 | volControl.Mute = not volControl.Mute |
|---|
| 87 | |
|---|
| 88 | def OnDown_Fn_F11(): |
|---|
| 89 | volControl.VolumeDown() |
|---|
| 90 | |
|---|
| 91 | def OnDown_Fn_F12(): |
|---|
| 92 | volControl.VolumeUp() |
|---|
| 93 | |
|---|
| 94 | """ |
|---|
| 95 | Fn+BackSpace -> Delete |
|---|
| 96 | """ |
|---|
| 97 | def OnDown_Fn_Back(): |
|---|
| 98 | Util.SendInput(Keys.Delete) |
|---|
| 99 | |
|---|
| 100 | """ |
|---|
| 101 | Fn+Delete -> VolumeUp (for F12 replaced by Delete) |
|---|
| 102 | """ |
|---|
| 103 | def OnDown_Fn_Delete(): |
|---|
| 104 | volControl.VolumeUp() |
|---|
| 105 | |
|---|
| 106 | """ |
|---|
| 107 | Fn+Up/Down -> PageUp/PageDown |
|---|
| 108 | """ |
|---|
| 109 | def OnDown_Fn_Up(): |
|---|
| 110 | Util.SendInput(Keys.PageUp) |
|---|
| 111 | |
|---|
| 112 | def OnDown_Fn_Down(): |
|---|
| 113 | Util.SendInput(Keys.PageDown) |
|---|
| 114 | |
|---|
| 115 | """ |
|---|
| 116 | Fn+Left/Right -> Home/End |
|---|
| 117 | """ |
|---|
| 118 | def OnDown_Fn_Left(): |
|---|
| 119 | Util.SendInput(Keys.Home) |
|---|
| 120 | |
|---|
| 121 | def OnDown_Fn_Right(): |
|---|
| 122 | Util.SendInput(Keys.End) |
|---|
| 123 | |
|---|
| 124 | # ---- |
|---|
| 125 | |
|---|
| 126 | # Create COM Object |
|---|
| 127 | def createObject(progID): |
|---|
| 128 | t = Type.GetTypeFromProgID(progID) |
|---|
| 129 | return Activator.CreateInstance(t) |
|---|
| 130 | |
|---|
| 131 | # iTunes Helper functions |
|---|
| 132 | def execiTunes(f): |
|---|
| 133 | it = createObject('iTunes.Application') |
|---|
| 134 | f(it) |
|---|
| 135 | Marshal.ReleaseComObject(it) |
|---|
| 136 | |
|---|
| 137 | # Show desktop |
|---|
| 138 | def toggleDesktop(): |
|---|
| 139 | shell = createObject('Shell.Application') |
|---|
| 140 | shell.ToggleDesktop() |
|---|
| 141 | Marshal.ReleaseComObject(shell) |
|---|