From d365eb62e4c85522f43ae6776bbdb3f93676a80e Mon Sep 17 00:00:00 2001 From: gered Date: Tue, 29 May 2012 11:06:41 -0400 Subject: [PATCH] add code from commit 8644 from codeplex sources --- .gitattributes | 49 +++ .gitignore | 165 ++++++++ AppleWirelessKeyboard.sln | 20 + AppleWirelessKeyboard/App.xaml | 4 + AppleWirelessKeyboard/App.xaml.cs | 104 +++++ AppleWirelessKeyboard/AppleKeyboardHID2.cs | 227 +++++++++++ .../AppleWirelessKeyboard.csproj | 358 ++++++++++++++++++ .../AppleWirelessKeyboard_TemporaryKey.pfx | Bin 0 -> 1652 bytes .../AUDIO_VOLUME_NOTIFICATION_DATA.cs | 54 +++ .../AudioEndPointVolumeVolumeRange.cs | 65 ++++ .../CoreAudioAPI/AudioEndpointVolume.cs | 157 ++++++++ .../AudioEndpointVolumeCallback.cs | 73 ++++ .../AudioEndpointVolumeChannel.cs | 71 ++++ .../AudioEndpointVolumeChannels.cs | 68 ++++ ...AudioEndpointVolumeNotificationDelegate.cs | 30 ++ .../AudioEndpointVolumeStepInformation.cs | 56 +++ .../CoreAudioAPI/AudioMeterInformation.cs | 79 ++++ .../AudioMeterInformationChannels.cs | 61 +++ .../CoreAudioAPI/AudioSessionControl.cs | 155 ++++++++ .../AudioSessionDisconnectReason.cs | 38 ++ .../CoreAudioAPI/AudioSessionManager.cs | 54 +++ .../CoreAudioAPI/AudioSessionState.cs | 35 ++ .../AudioVolumeNotificationData.cs | 83 ++++ AppleWirelessKeyboard/CoreAudioAPI/Blob.cs | 47 +++ AppleWirelessKeyboard/CoreAudioAPI/CLSCTX.cs | 53 +++ .../CoreAudioAPI/EDataFlow.cs | 35 ++ .../CoreAudioAPI/EDeviceState.cs | 36 ++ .../CoreAudioAPI/EEndpointHardwareSupport.cs | 35 ++ AppleWirelessKeyboard/CoreAudioAPI/ERole.cs | 35 ++ .../CoreAudioAPI/IAudioEndpointVolume.cs | 70 ++++ .../IAudioEndpointVolumeCallback.cs | 36 ++ .../CoreAudioAPI/IAudioMeterInformation.cs | 42 ++ .../CoreAudioAPI/IAudioPeakMeter.cs | 37 ++ .../CoreAudioAPI/IAudioSessionControl2.cs | 66 ++++ .../CoreAudioAPI/IAudioSessionEnumerator.cs | 34 ++ .../CoreAudioAPI/IAudioSessionEvents.cs | 48 +++ .../CoreAudioAPI/IAudioSessionManager2.cs | 49 +++ .../CoreAudioAPI/IMMDevice.cs | 42 ++ .../CoreAudioAPI/IMMDeviceCollection.cs | 38 ++ .../CoreAudioAPI/IMMDeviceEnumerator.cs | 44 +++ .../CoreAudioAPI/IMMEndpoint.cs | 36 ++ .../CoreAudioAPI/IPropertyStore.cs | 44 +++ .../CoreAudioAPI/ISimpleAudioVolume.cs | 43 +++ .../CoreAudioAPI/MMDevice.cs | 180 +++++++++ .../CoreAudioAPI/MMDeviceCollection.cs | 59 +++ .../CoreAudioAPI/MMDeviceEnumerator.cs | 70 ++++ AppleWirelessKeyboard/CoreAudioAPI/PKEY.cs | 41 ++ .../CoreAudioAPI/PropVariant.cs | 96 +++++ .../CoreAudioAPI/PropertyKey.cs | 34 ++ .../CoreAudioAPI/PropertyStore.cs | 107 ++++++ .../CoreAudioAPI/PropertyStoreProperty.cs | 57 +++ .../CoreAudioAPI/SessionCollection.cs | 60 +++ .../CoreAudioAPI/SimpleAudioVolume.cs | 70 ++++ .../CoreAudioAPI/eStgmAccess.cs | 34 ++ AppleWirelessKeyboard/Glyphs/Eject.xaml | 9 + AppleWirelessKeyboard/Glyphs/Eject.xaml.cs | 27 ++ AppleWirelessKeyboard/Glyphs/MuteOff.xaml | 13 + AppleWirelessKeyboard/Glyphs/MuteOff.xaml.cs | 27 ++ AppleWirelessKeyboard/Glyphs/MuteOn.xaml | 11 + AppleWirelessKeyboard/Glyphs/MuteOn.xaml.cs | 27 ++ AppleWirelessKeyboard/Glyphs/Next.xaml | 8 + AppleWirelessKeyboard/Glyphs/Next.xaml.cs | 27 ++ AppleWirelessKeyboard/Glyphs/Off.xaml | 7 + AppleWirelessKeyboard/Glyphs/Off.xaml.cs | 27 ++ AppleWirelessKeyboard/Glyphs/On.xaml | 7 + AppleWirelessKeyboard/Glyphs/On.xaml.cs | 27 ++ AppleWirelessKeyboard/Glyphs/PlayPause.xaml | 9 + .../Glyphs/PlayPause.xaml.cs | 27 ++ AppleWirelessKeyboard/Glyphs/Previous.xaml | 8 + AppleWirelessKeyboard/Glyphs/Previous.xaml.cs | 27 ++ AppleWirelessKeyboard/Glyphs/PrintScreen.xaml | 15 + .../Glyphs/PrintScreen.xaml.cs | 27 ++ AppleWirelessKeyboard/Glyphs/TaskManager.xaml | 10 + .../Glyphs/TaskManager.xaml.cs | 27 ++ AppleWirelessKeyboard/Glyphs/VolumeOff.xaml | 14 + .../Glyphs/VolumeOff.xaml.cs | 27 ++ AppleWirelessKeyboard/Glyphs/VolumeOn.xaml | 17 + AppleWirelessKeyboard/Glyphs/VolumeOn.xaml.cs | 27 ++ ...Preferences-Desktop-Keyboard-Shortcuts.ico | Bin 0 -> 34499 bytes AppleWirelessKeyboard/HIDImports.cs | 192 ++++++++++ AppleWirelessKeyboard/IoControl.cs | 67 ++++ AppleWirelessKeyboard/KeyboardControl.cs | 172 +++++++++ AppleWirelessKeyboard/KeyboardHandler.cs | 168 ++++++++ AppleWirelessKeyboard/KeyboardListener.cs | 210 ++++++++++ AppleWirelessKeyboard/MainWindow.xaml | 15 + AppleWirelessKeyboard/MainWindow.xaml.cs | 60 +++ AppleWirelessKeyboard/NotificationCenter.cs | 100 +++++ AppleWirelessKeyboard/PowerControl.cs | 41 ++ AppleWirelessKeyboard/PowerStatusBox.xaml | 16 + AppleWirelessKeyboard/PowerStatusBox.xaml.cs | 104 +++++ .../Properties/AssemblyInfo.cs | 55 +++ .../Properties/Resources.Designer.cs | 63 +++ .../Properties/Resources.resx | 117 ++++++ .../Properties/Settings.Designer.cs | 86 +++++ .../Properties/Settings.settings | 21 + AppleWirelessKeyboard/StartupShortcut.cs | 37 ++ AppleWirelessKeyboard/TrayIcon.cs | 55 +++ .../Views/Configuration.xaml | 22 ++ .../Views/Configuration.xaml.cs | 26 ++ AppleWirelessKeyboard/VolumeControl.cs | 48 +++ AppleWirelessKeyboard/app.config | 27 ++ AppleWirelessKeyboard/iTunesControl.cs | 40 ++ AppleWirelessKeyboard/uxsoft.cs | 90 +++++ 103 files changed, 5968 insertions(+) create mode 100644 .gitattributes create mode 100644 .gitignore create mode 100644 AppleWirelessKeyboard.sln create mode 100644 AppleWirelessKeyboard/App.xaml create mode 100644 AppleWirelessKeyboard/App.xaml.cs create mode 100644 AppleWirelessKeyboard/AppleKeyboardHID2.cs create mode 100644 AppleWirelessKeyboard/AppleWirelessKeyboard.csproj create mode 100644 AppleWirelessKeyboard/AppleWirelessKeyboard_TemporaryKey.pfx create mode 100644 AppleWirelessKeyboard/CoreAudioAPI/AUDIO_VOLUME_NOTIFICATION_DATA.cs create mode 100644 AppleWirelessKeyboard/CoreAudioAPI/AudioEndPointVolumeVolumeRange.cs create mode 100644 AppleWirelessKeyboard/CoreAudioAPI/AudioEndpointVolume.cs create mode 100644 AppleWirelessKeyboard/CoreAudioAPI/AudioEndpointVolumeCallback.cs create mode 100644 AppleWirelessKeyboard/CoreAudioAPI/AudioEndpointVolumeChannel.cs create mode 100644 AppleWirelessKeyboard/CoreAudioAPI/AudioEndpointVolumeChannels.cs create mode 100644 AppleWirelessKeyboard/CoreAudioAPI/AudioEndpointVolumeNotificationDelegate.cs create mode 100644 AppleWirelessKeyboard/CoreAudioAPI/AudioEndpointVolumeStepInformation.cs create mode 100644 AppleWirelessKeyboard/CoreAudioAPI/AudioMeterInformation.cs create mode 100644 AppleWirelessKeyboard/CoreAudioAPI/AudioMeterInformationChannels.cs create mode 100644 AppleWirelessKeyboard/CoreAudioAPI/AudioSessionControl.cs create mode 100644 AppleWirelessKeyboard/CoreAudioAPI/AudioSessionDisconnectReason.cs create mode 100644 AppleWirelessKeyboard/CoreAudioAPI/AudioSessionManager.cs create mode 100644 AppleWirelessKeyboard/CoreAudioAPI/AudioSessionState.cs create mode 100644 AppleWirelessKeyboard/CoreAudioAPI/AudioVolumeNotificationData.cs create mode 100644 AppleWirelessKeyboard/CoreAudioAPI/Blob.cs create mode 100644 AppleWirelessKeyboard/CoreAudioAPI/CLSCTX.cs create mode 100644 AppleWirelessKeyboard/CoreAudioAPI/EDataFlow.cs create mode 100644 AppleWirelessKeyboard/CoreAudioAPI/EDeviceState.cs create mode 100644 AppleWirelessKeyboard/CoreAudioAPI/EEndpointHardwareSupport.cs create mode 100644 AppleWirelessKeyboard/CoreAudioAPI/ERole.cs create mode 100644 AppleWirelessKeyboard/CoreAudioAPI/IAudioEndpointVolume.cs create mode 100644 AppleWirelessKeyboard/CoreAudioAPI/IAudioEndpointVolumeCallback.cs create mode 100644 AppleWirelessKeyboard/CoreAudioAPI/IAudioMeterInformation.cs create mode 100644 AppleWirelessKeyboard/CoreAudioAPI/IAudioPeakMeter.cs create mode 100644 AppleWirelessKeyboard/CoreAudioAPI/IAudioSessionControl2.cs create mode 100644 AppleWirelessKeyboard/CoreAudioAPI/IAudioSessionEnumerator.cs create mode 100644 AppleWirelessKeyboard/CoreAudioAPI/IAudioSessionEvents.cs create mode 100644 AppleWirelessKeyboard/CoreAudioAPI/IAudioSessionManager2.cs create mode 100644 AppleWirelessKeyboard/CoreAudioAPI/IMMDevice.cs create mode 100644 AppleWirelessKeyboard/CoreAudioAPI/IMMDeviceCollection.cs create mode 100644 AppleWirelessKeyboard/CoreAudioAPI/IMMDeviceEnumerator.cs create mode 100644 AppleWirelessKeyboard/CoreAudioAPI/IMMEndpoint.cs create mode 100644 AppleWirelessKeyboard/CoreAudioAPI/IPropertyStore.cs create mode 100644 AppleWirelessKeyboard/CoreAudioAPI/ISimpleAudioVolume.cs create mode 100644 AppleWirelessKeyboard/CoreAudioAPI/MMDevice.cs create mode 100644 AppleWirelessKeyboard/CoreAudioAPI/MMDeviceCollection.cs create mode 100644 AppleWirelessKeyboard/CoreAudioAPI/MMDeviceEnumerator.cs create mode 100644 AppleWirelessKeyboard/CoreAudioAPI/PKEY.cs create mode 100644 AppleWirelessKeyboard/CoreAudioAPI/PropVariant.cs create mode 100644 AppleWirelessKeyboard/CoreAudioAPI/PropertyKey.cs create mode 100644 AppleWirelessKeyboard/CoreAudioAPI/PropertyStore.cs create mode 100644 AppleWirelessKeyboard/CoreAudioAPI/PropertyStoreProperty.cs create mode 100644 AppleWirelessKeyboard/CoreAudioAPI/SessionCollection.cs create mode 100644 AppleWirelessKeyboard/CoreAudioAPI/SimpleAudioVolume.cs create mode 100644 AppleWirelessKeyboard/CoreAudioAPI/eStgmAccess.cs create mode 100644 AppleWirelessKeyboard/Glyphs/Eject.xaml create mode 100644 AppleWirelessKeyboard/Glyphs/Eject.xaml.cs create mode 100644 AppleWirelessKeyboard/Glyphs/MuteOff.xaml create mode 100644 AppleWirelessKeyboard/Glyphs/MuteOff.xaml.cs create mode 100644 AppleWirelessKeyboard/Glyphs/MuteOn.xaml create mode 100644 AppleWirelessKeyboard/Glyphs/MuteOn.xaml.cs create mode 100644 AppleWirelessKeyboard/Glyphs/Next.xaml create mode 100644 AppleWirelessKeyboard/Glyphs/Next.xaml.cs create mode 100644 AppleWirelessKeyboard/Glyphs/Off.xaml create mode 100644 AppleWirelessKeyboard/Glyphs/Off.xaml.cs create mode 100644 AppleWirelessKeyboard/Glyphs/On.xaml create mode 100644 AppleWirelessKeyboard/Glyphs/On.xaml.cs create mode 100644 AppleWirelessKeyboard/Glyphs/PlayPause.xaml create mode 100644 AppleWirelessKeyboard/Glyphs/PlayPause.xaml.cs create mode 100644 AppleWirelessKeyboard/Glyphs/Previous.xaml create mode 100644 AppleWirelessKeyboard/Glyphs/Previous.xaml.cs create mode 100644 AppleWirelessKeyboard/Glyphs/PrintScreen.xaml create mode 100644 AppleWirelessKeyboard/Glyphs/PrintScreen.xaml.cs create mode 100644 AppleWirelessKeyboard/Glyphs/TaskManager.xaml create mode 100644 AppleWirelessKeyboard/Glyphs/TaskManager.xaml.cs create mode 100644 AppleWirelessKeyboard/Glyphs/VolumeOff.xaml create mode 100644 AppleWirelessKeyboard/Glyphs/VolumeOff.xaml.cs create mode 100644 AppleWirelessKeyboard/Glyphs/VolumeOn.xaml create mode 100644 AppleWirelessKeyboard/Glyphs/VolumeOn.xaml.cs create mode 100644 AppleWirelessKeyboard/Gnome-Preferences-Desktop-Keyboard-Shortcuts.ico create mode 100644 AppleWirelessKeyboard/HIDImports.cs create mode 100644 AppleWirelessKeyboard/IoControl.cs create mode 100644 AppleWirelessKeyboard/KeyboardControl.cs create mode 100644 AppleWirelessKeyboard/KeyboardHandler.cs create mode 100644 AppleWirelessKeyboard/KeyboardListener.cs create mode 100644 AppleWirelessKeyboard/MainWindow.xaml create mode 100644 AppleWirelessKeyboard/MainWindow.xaml.cs create mode 100644 AppleWirelessKeyboard/NotificationCenter.cs create mode 100644 AppleWirelessKeyboard/PowerControl.cs create mode 100644 AppleWirelessKeyboard/PowerStatusBox.xaml create mode 100644 AppleWirelessKeyboard/PowerStatusBox.xaml.cs create mode 100644 AppleWirelessKeyboard/Properties/AssemblyInfo.cs create mode 100644 AppleWirelessKeyboard/Properties/Resources.Designer.cs create mode 100644 AppleWirelessKeyboard/Properties/Resources.resx create mode 100644 AppleWirelessKeyboard/Properties/Settings.Designer.cs create mode 100644 AppleWirelessKeyboard/Properties/Settings.settings create mode 100644 AppleWirelessKeyboard/StartupShortcut.cs create mode 100644 AppleWirelessKeyboard/TrayIcon.cs create mode 100644 AppleWirelessKeyboard/Views/Configuration.xaml create mode 100644 AppleWirelessKeyboard/Views/Configuration.xaml.cs create mode 100644 AppleWirelessKeyboard/VolumeControl.cs create mode 100644 AppleWirelessKeyboard/app.config create mode 100644 AppleWirelessKeyboard/iTunesControl.cs create mode 100644 AppleWirelessKeyboard/uxsoft.cs diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..a664be3 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,49 @@ +*.doc diff=astextplain +*.DOC diff=astextplain +*.docx diff=astextplain +*.DOCX diff=astextplain +*.dot diff=astextplain +*.DOT diff=astextplain +*.pdf diff=astextplain +*.PDF diff=astextplain +*.rtf diff=astextplain +*.RTF diff=astextplain + +*.jpg binary +*.png binary +*.gif binary + +*.cs text=auto diff=csharp +*.vb text=auto +*.c text=auto +*.cpp text=auto +*.cxx text=auto +*.h text=auto +*.hxx text=auto +*.py text=auto +*.rb text=auto +*.java text=auto +*.html text=auto +*.htm text=auto +*.css text=auto +*.scss text=auto +*.sass text=auto +*.less text=auto +*.js text=auto +*.lisp text=auto +*.clj text=auto +*.sql text=auto +*.php text=auto +*.lua text=auto +*.m text=auto +*.asm text=auto +*.erl text=auto +*.fs text=auto +*.fsx text=auto +*.hs text=auto + +*.csproj text=auto merge=union +*.vbproj text=auto merge=union +*.fsproj text=auto merge=union +*.dbproj text=auto merge=union +*.sln text=auto eol=crlf merge=union diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..aa8811c --- /dev/null +++ b/.gitignore @@ -0,0 +1,165 @@ + +################# +## Eclipse +################# + +*.pydevproject +.project +.metadata +bin/** +tmp/** +tmp/**/* +*.tmp +*.bak +*.swp +*~.nib +local.properties +.classpath +.settings/ +.loadpath + +# External tool builders +.externalToolBuilders/ + +# Locally stored "Eclipse launch configurations" +*.launch + +# CDT-specific +.cproject + +# PDT-specific +.buildpath + + +################# +## Visual Studio +################# + +## Ignore Visual Studio temporary files, build results, and +## files generated by popular Visual Studio add-ons. + +# User-specific files +*.suo +*.user +*.sln.docstates + +# Build results +**/[Dd]ebug/ +**/[Rr]elease/ +*_i.c +*_p.c +*.ilk +*.meta +*.obj +*.pch +*.pdb +*.pgc +*.pgd +*.rsp +*.sbr +*.tlb +*.tli +*.tlh +*.tmp +*.vspscc +.builds +**/*.dotCover + +## TODO: If you have NuGet Package Restore enabled, uncomment this +#**/packages/ + +# Visual C++ cache files +ipch/ +*.aps +*.ncb +*.opensdf +*.sdf + +# Visual Studio profiler +*.psess +*.vsp + +# ReSharper is a .NET coding add-in +_ReSharper* + +# Installshield output folder +[Ee]xpress + +# DocProject is a documentation generator add-in +DocProject/buildhelp/ +DocProject/Help/*.HxT +DocProject/Help/*.HxC +DocProject/Help/*.hhc +DocProject/Help/*.hhk +DocProject/Help/*.hhp +DocProject/Help/Html2 +DocProject/Help/html + +# Click-Once directory +publish + +# Others +[Bb]in +[Oo]bj +sql +TestResults +*.Cache +ClientBin +stylecop.* +~$* +*.dbmdl +Generated_Code #added for RIA/Silverlight projects + +# Backup & report files from converting an old project file to a newer +# Visual Studio version. Backup files are not needed, because we have git ;-) +_UpgradeReport_Files/ +Backup*/ +UpgradeLog*.XML + + + +############ +## Windows +############ + +# Windows image file caches +Thumbs.db + +# Folder config file +Desktop.ini + + +############# +## Python +############# + +*.py[co] + +# Packages +*.egg +*.egg-info +dist +build +eggs +parts +bin +var +sdist +develop-eggs +.installed.cfg + +# Installer logs +pip-log.txt + +# Unit test / coverage reports +.coverage +.tox + +#Translations +*.mo + +#Mr Developer +.mr.developer.cfg + +# Mac crap +.DS_Store diff --git a/AppleWirelessKeyboard.sln b/AppleWirelessKeyboard.sln new file mode 100644 index 0000000..6abc3e9 --- /dev/null +++ b/AppleWirelessKeyboard.sln @@ -0,0 +1,20 @@ + +Microsoft Visual Studio Solution File, Format Version 11.00 +# Visual Studio 2010 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AppleWirelessKeyboard", "AppleWirelessKeyboard\AppleWirelessKeyboard.csproj", "{9654B149-302A-4392-8F91-4202FA6E0AE4}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|x86 = Debug|x86 + Release|x86 = Release|x86 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {9654B149-302A-4392-8F91-4202FA6E0AE4}.Debug|x86.ActiveCfg = Debug|x86 + {9654B149-302A-4392-8F91-4202FA6E0AE4}.Debug|x86.Build.0 = Debug|x86 + {9654B149-302A-4392-8F91-4202FA6E0AE4}.Release|x86.ActiveCfg = Release|x86 + {9654B149-302A-4392-8F91-4202FA6E0AE4}.Release|x86.Build.0 = Release|x86 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/AppleWirelessKeyboard/App.xaml b/AppleWirelessKeyboard/App.xaml new file mode 100644 index 0000000..42ccf36 --- /dev/null +++ b/AppleWirelessKeyboard/App.xaml @@ -0,0 +1,4 @@ + diff --git a/AppleWirelessKeyboard/App.xaml.cs b/AppleWirelessKeyboard/App.xaml.cs new file mode 100644 index 0000000..33ef59e --- /dev/null +++ b/AppleWirelessKeyboard/App.xaml.cs @@ -0,0 +1,104 @@ +using System; +using System.Collections.Generic; +using System.Configuration; +using System.Data; +using System.Linq; +using System.Windows; +using System.Windows.Input; +using System.Diagnostics; +using System.Timers; +using System.Threading; + +namespace AppleWirelessKeyboard +{ + /// + /// Interaction logic for App.xaml + /// + public partial class App : Application + { + public static MainWindow Window { get; set; } + + private void Application_Startup(object sender, StartupEventArgs e) + { + TrayIcon.Show(); + uxsoft.VersionCheck(); + + if (!StartupShortcut.IsRegistered) + StartupShortcut.Register(); + + if (Process.GetProcessesByName(Application.ResourceAssembly.GetName().Name).Length > 1) + { + var processes = Process.GetProcessesByName(Application.ResourceAssembly.GetName().Name); + foreach (Process p in processes) + if (p != Process.GetCurrentProcess()) + p.Kill(); + } + + Window = new MainWindow(); + + AppleKeyboardHID2.Start(); + AppleKeyboardHID2.KeyDown += new AppleKeyboardHID2.AppleHIDKeyboardEventHandler(AppleKeyboardHID_KeyDown); + AppleKeyboardHID2.KeyUp += new AppleKeyboardHID2.AppleHIDKeyboardEventHandler(AppleKeyboardHID_KeyUp); + + KeyboardListener.HookedKeys.Add(Key.F2); + KeyboardListener.HookedKeys.Add(Key.F3); + KeyboardListener.HookedKeys.Add(Key.F4); + KeyboardListener.HookedKeys.Add(Key.F7); + KeyboardListener.HookedKeys.Add(Key.F8); + KeyboardListener.HookedKeys.Add(Key.F9); + KeyboardListener.HookedKeys.Add(Key.F10); + KeyboardListener.HookedKeys.Add(Key.F11); + KeyboardListener.HookedKeys.Add(Key.F12); + KeyboardListener.HookedKeys.Add(Key.Back); + KeyboardListener.HookedKeys.Add(Key.Up); + KeyboardListener.HookedKeys.Add(Key.Left); + KeyboardListener.HookedKeys.Add(Key.Right); + KeyboardListener.HookedKeys.Add(Key.Down); + KeyboardListener.HookedKeys.Add(Key.Enter); + KeyboardListener.Register(); + KeyboardListener.KeyDown += new KeyboardListener.KeyHookEventHandler(KeyboardListener_KeyDown); + + Microsoft.Win32.SystemEvents.PowerModeChanged += new Microsoft.Win32.PowerModeChangedEventHandler(SystemEvents_PowerModeChanged); + } + + void SystemEvents_PowerModeChanged(object sender, Microsoft.Win32.PowerModeChangedEventArgs e) + { + if (e.Mode == Microsoft.Win32.PowerModes.Resume) + { + Thread.Sleep(16000); + AppleKeyboardHID2.Shutdown(); + AppleKeyboardHID2.Start(); + } + } + + void AppleKeyboardHID_KeyUp(AppleKeyboardSpecialKeys key) + { + if (key == AppleKeyboardSpecialKeys.Fn) + KeyboardListener.ModifierFn = false; + } + + void AppleKeyboardHID_KeyDown(AppleKeyboardSpecialKeys key) + { + switch (key) + { + case AppleKeyboardSpecialKeys.Fn: + KeyboardListener.ModifierFn = true; + break; + case AppleKeyboardSpecialKeys.Eject: + KeyboardHandler.HandleEject(); + break; + } + } + + bool KeyboardListener_KeyDown(KeyboardListener.KeyHookEventArgs e) + { + return KeyboardHandler.HandleKeyDown(e); + } + + private void Application_Exit(object sender, ExitEventArgs e) + { + KeyboardListener.UnRegister(); + AppleKeyboardHID2.Shutdown(); + } + } +} diff --git a/AppleWirelessKeyboard/AppleKeyboardHID2.cs b/AppleWirelessKeyboard/AppleKeyboardHID2.cs new file mode 100644 index 0000000..60795c5 --- /dev/null +++ b/AppleWirelessKeyboard/AppleKeyboardHID2.cs @@ -0,0 +1,227 @@ +using System; +using System.IO; +using AppleWirelessKeyboard; +using System.Runtime.InteropServices; +using Microsoft.Win32.SafeHandles; +using System.Windows.Forms; +using System.Diagnostics; +using System.Threading; + +namespace AppleWirelessKeyboard +{ + public class AppleKeyboardHID2 + { + // Fields + static Stream _stream; + static bool CurrentPowerButtonIsDown; + public const int VIDApple = 0x5ac; + + // Events + public static event EventHandler Disconnected; + public delegate void AppleHIDKeyboardEventHandler(AppleKeyboardSpecialKeys key); + public static event AppleHIDKeyboardEventHandler KeyUp; + public static event AppleHIDKeyboardEventHandler KeyDown; + + //Properties + public static bool FnDown { get; set; } + public static bool EjectDown { get; set; } + public static bool PowerButtonDown { get; set; } + public static bool Registered + { + get { return _stream != null; } + } + + public static void Shutdown() + { + if (_stream != null) + { + _stream.Close(); + _stream = null; + } + } + + private static void SpecialKeyStateChanged(IAsyncResult ar) + { + if ((_stream != null) && ar.IsCompleted) + { + try + { + _stream.EndRead(ar); + } + catch (OperationCanceledException) + { + } + catch (IOException) + { + if (Disconnected != null) + { + Disconnected(null, EventArgs.Empty); + } + return; + } + byte[] asyncState = ar.AsyncState as byte[]; + byte[] buffer2 = asyncState; + for (int i = 0; i < buffer2.Length; i++) + { + byte num1 = buffer2[i]; + } + if (asyncState[0] == 0x11) + { + switch (asyncState[1]) + { + case 24: + { + EjectDown = true; + FnDown = true; + if (KeyDown != null) + KeyDown(AppleKeyboardSpecialKeys.Eject); + } + break; + case 16: + { + if (EjectDown) + { + EjectDown = false; + if (KeyUp != null) + KeyUp(AppleKeyboardSpecialKeys.Eject); + } + FnDown = true; + if (KeyDown != null) + KeyDown(AppleKeyboardSpecialKeys.Fn); + } + break; + case 8: + { + if (FnDown) + { + FnDown = false; + if (KeyUp != null) + KeyUp(AppleKeyboardSpecialKeys.Fn); + } + EjectDown = true; + if (KeyDown != null) + KeyDown(AppleKeyboardSpecialKeys.Eject); + } + break; + case 0: + { + if (EjectDown) + { + EjectDown = false; + if (KeyUp != null) + KeyUp(AppleKeyboardSpecialKeys.Eject); + } + if (FnDown) + { + FnDown = false; + if (KeyUp != null) + KeyUp(AppleKeyboardSpecialKeys.Fn); + } + } + break; + } + } + else if (asyncState[0] == 0x13) + { + CurrentPowerButtonIsDown = asyncState[1] == 1; + } + _stream.BeginRead(asyncState, 0, asyncState.Length, new AsyncCallback(SpecialKeyStateChanged), asyncState); + } + } + + public static bool Start() + { + Guid guid; + HIDImports.SP_DEVICE_INTERFACE_DATA sp_device_interface_data = new HIDImports.SP_DEVICE_INTERFACE_DATA() { cbSize = Marshal.SizeOf(typeof(HIDImports.SP_DEVICE_INTERFACE_DATA)) }; + + if (_stream != null) + { + throw new InvalidOperationException("No Stream!"); + } + + HIDImports.HidD_GetHidGuid(out guid); + IntPtr hDevInfo = HIDImports.SetupDiGetClassDevs(ref guid, null, IntPtr.Zero, 0x10); + + int num = 0; + while (HIDImports.SetupDiEnumDeviceInterfaces(hDevInfo, IntPtr.Zero, ref guid, num++, ref sp_device_interface_data)) + { + uint num2; + HIDImports.SP_DEVICE_INTERFACE_DETAIL_DATA deviceInterfaceDetailData = new HIDImports.SP_DEVICE_INTERFACE_DETAIL_DATA { cbSize = (IntPtr.Size == 8) ? (uint)8 : (uint)5 }; + + HIDImports.SetupDiGetDeviceInterfaceDetail(hDevInfo, ref sp_device_interface_data, IntPtr.Zero, 0, out num2, IntPtr.Zero); + if (HIDImports.SetupDiGetDeviceInterfaceDetail(hDevInfo, ref sp_device_interface_data, ref deviceInterfaceDetailData, num2, out num2, IntPtr.Zero)) + { + HIDImports.HIDD_ATTRIBUTES hidd_attributes = new HIDImports.HIDD_ATTRIBUTES() { Size = Marshal.SizeOf(typeof(HIDImports.HIDD_ATTRIBUTES)) }; + + SafeFileHandle handle = HIDImports.CreateFile(deviceInterfaceDetailData.DevicePath, FileAccess.ReadWrite, FileShare.ReadWrite, IntPtr.Zero, FileMode.Open, HIDImports.EFileAttributes.Overlapped, IntPtr.Zero); + + if (HIDImports.HidD_GetAttributes(handle.DangerousGetHandle(), ref hidd_attributes)) + { + if (IsAppleWirelessKeyboard(hidd_attributes.VendorID, hidd_attributes.ProductID)) + { + _stream = new FileStream(handle, FileAccess.ReadWrite, 0x16, true); + //break; + } + else + { + handle.Close(); + } + } + } + } + + HIDImports.SetupDiDestroyDeviceInfoList(hDevInfo); + + if (_stream != null) + { + byte[] buffer = new byte[0x16]; + _stream.BeginRead(buffer, 0, buffer.Length, new AsyncCallback(SpecialKeyStateChanged), buffer); + return true; + } + return false; + } + + private static bool IsAppleWirelessKeyboard(int vid, int pid) + { + if (vid == VIDApple) + { + Guid HIDGUID; + HIDImports.HidD_GetHidGuid(out HIDGUID); + + IntPtr DeviceInfo = HIDImports.SetupDiGetClassDevs(ref HIDGUID, null, IntPtr.Zero, 16); + + uint MemberIndex = 0; + + HIDImports.SP_DEVINFO_DATA DID = new HIDImports.SP_DEVINFO_DATA() { cbSize = (uint)Marshal.SizeOf(typeof(HIDImports.SP_DEVINFO_DATA)) }; + + while (HIDImports.SetupDiEnumDeviceInfo(DeviceInfo, MemberIndex++, ref DID)) + { + uint RequiredSize = 0; + uint PropertyDataType = 0; + IntPtr buffer = Marshal.AllocHGlobal(512); + string CLASS = ""; + + + if (HIDImports.SetupDiGetDeviceRegistryProperty(DeviceInfo, ref DID, (uint)HIDImports.SPDRP.SPDRP_CLASS, out PropertyDataType, buffer, 512, out RequiredSize)) + CLASS = Marshal.PtrToStringAuto(buffer); + + if (CLASS.Equals("Keyboard", StringComparison.InvariantCultureIgnoreCase)) + return true; + } + + HIDImports.SetupDiDestroyDeviceInfoList(DeviceInfo); + + return true; + } + else return false; + } + } + public enum AppleKeyboardSpecialKeys : byte + { + //Fn + Eject = 24 + Fn = 16, + Eject = 8, + PowerButton = 3 + //None = 0 + } +} \ No newline at end of file diff --git a/AppleWirelessKeyboard/AppleWirelessKeyboard.csproj b/AppleWirelessKeyboard/AppleWirelessKeyboard.csproj new file mode 100644 index 0000000..901b2c3 --- /dev/null +++ b/AppleWirelessKeyboard/AppleWirelessKeyboard.csproj @@ -0,0 +1,358 @@ + + + + Debug + x86 + 8.0.30703 + 2.0 + {9654B149-302A-4392-8F91-4202FA6E0AE4} + WinExe + Properties + AppleWirelessKeyboard + AppleWirelessKeyboard + v4.0 + Client + 512 + {60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + 4 + true + OnOutputUpdated + + + + + + + + + publish\ + true + Web + true + Background + 7 + Days + false + false + true + http://applewirelesskbrd.codeplex.com/releases/clickonce/ + http://applewirelesskbrd.codeplex.com/releases/clickonce/ + http://applewirelesskbrd.codeplex.com + AppleWirelessKeyboard + X-soft + AppleWirelessKeyboard + true + publish.htm + false + true + 0 + 2.1.0.0 + false + true + true + + + AnyCPU + true + full + true + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + 902A841B3FDD641CBAF24748EC3D69DFF5ECCF12 + + + AppleWirelessKeyboard_TemporaryKey.pfx + + + true + + + true + + + Gnome-Preferences-Desktop-Keyboard-Shortcuts.ico + + + AppleWirelessKeyboard.App + + + + + + + + + + + + + + + 4.0 + + + + + + + + MSBuild:Compile + Designer + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Eject.xaml + + + MuteOff.xaml + + + MuteOn.xaml + + + Next.xaml + + + Off.xaml + + + On.xaml + + + PlayPause.xaml + + + Previous.xaml + + + PrintScreen.xaml + + + TaskManager.xaml + + + VolumeOff.xaml + + + VolumeOn.xaml + + + + + + + + + + + PowerStatusBox.xaml + + + + + + Configuration.xaml + + + + Designer + MSBuild:Compile + + + Designer + MSBuild:Compile + + + Designer + MSBuild:Compile + + + Designer + MSBuild:Compile + + + Designer + MSBuild:Compile + + + Designer + MSBuild:Compile + + + Designer + MSBuild:Compile + + + Designer + MSBuild:Compile + + + Designer + MSBuild:Compile + + + Designer + MSBuild:Compile + + + Designer + MSBuild:Compile + + + Designer + MSBuild:Compile + + + MSBuild:Compile + Designer + + + App.xaml + Code + + + MainWindow.xaml + Code + + + Designer + MSBuild:Compile + + + Designer + MSBuild:Compile + + + + + Code + + + True + True + Resources.resx + + + True + Settings.settings + True + + + ResXFileCodeGenerator + Resources.Designer.cs + + + + + SettingsSingleFileGenerator + Settings.Designer.cs + + + + + + False + Microsoft .NET Framework 4 Client Profile %28x86 and x64%29 + true + + + False + .NET Framework 3.5 SP1 Client Profile + false + + + False + .NET Framework 3.5 SP1 + false + + + False + Windows Installer 3.1 + true + + + + + + + + {9E93C96F-CF0D-43F6-8BA8-B807A3370712} + 1 + 13 + 0 + tlbimp + False + True + + + + + + if /I "$(ConfigurationName)" == "Release" Eazfuscator.NET.exe "$(TargetPath)" --msbuild-project-path "$(ProjectPath)" --msbuild-project-configuration "$(ConfigurationName)" --msbuild-project-platform "$(PlatformName)" -n --newline-flush -v 2.9 + + \ No newline at end of file diff --git a/AppleWirelessKeyboard/AppleWirelessKeyboard_TemporaryKey.pfx b/AppleWirelessKeyboard/AppleWirelessKeyboard_TemporaryKey.pfx new file mode 100644 index 0000000000000000000000000000000000000000..2a18f544e95f80afee3a44824fed56eba7ccbf9b GIT binary patch literal 1652 zcmY+DdpOg39LK+#`Dx5VLuRx*J;I93JyL2@I))r{MQvzv$+aYw%UYh1kaAR8H%^p9 zsW3*%+*0HgiR4lUr%qwjI&^+|&Z(#8_q>1K_viKbe!kE5kMEnzg(8p$1u_>}1EEb) zoKrrjB9stUxR4%-3+cdElgw2p|D~l+h~g^b!}u~R0i^QZ6h;|=yuwA6lex$;G67Ql zAH#=ZQA_G}kBC^zVFD7V)Q;jJv+A#F4EMAO*I@3fFdE}mRjgV1DcdS8U-RNzcif1; zi_ZRL=k_+Gmv^hTIP_^1OB*Y;F%WdBXO2%cj4fNgbEWLL zTY1Z;=mnL_xf-#dGnIcR1LBE+oP=g5WWRgdjx|@OdSYLfO^P4P$BD;s=^J&XK3`oS zkFzeCjLh98(k*sfI38u35gR(y_v+8`jx>{xZQ8qvM*oq})1C`9v^H6?539R8!{3@4 zQ7*Q4(bn8V$6gA?X*uR==~=Z5rQ^`8T_MNZ!w0GH!p*{=n%(nGNrC74YPe~eVx5k# zB44I|zU5eIENuRmJy|xzXc1|@;js_7T=Ej=DaEOh=hW0`Z?$_4MDgVhggcfc>T<$7 zLPRpYWJXXY5^c|kWSN{}pB*{wOUMj?1ZoHOzauIuzL|4Q6zfawe6ry`W^>mIJzWS}R<@YXTxX%U7?I-@e_leYryLR5y&wQ#)Zd_fcm_+9UJ9g={-=|TY zkBhf`6k&#Mu=FwhOe2|k>VcQ0Nrg)moF(6c+M;wmXDClA_P*Op4A0dq%qJ$;mN4!D zG7oHuH!xF_7JBE+HP)!E*3~WY-BYfYw`=;aDDf)KT1#0d(ZNJg*D+S%tMD5yFg$&9 zrt~zt0v^_0{Kn|4|GSP|ax_bSrOPG=a= zkO%-T4nI4HU*ZZa#NRcLP+#(6L1~%Qx$JQB z37Qo2GjJS>ZB4;FeyZsegO69cYrbcwlp0HOs zY)N@?m&ut^mt8VuJ;bNto01b*BXVIY$!}v_XVY|dc)KD;00*;-W`*{8-We=kO}V*Q z&o9BaJaTjWDQ*{7Z$h$#={M&=#B^R=tl z!!uqrhNbdKq)kw(%0biFEB1s((kA!yuD1852b+hBifdP4uw$hGS%$Q*j!Wb39a}G+ z^pVBotfJn#P(2tsftsyl5%}33L`M#9+Iu?Y_y&gDw18|+UO`rZ6iHYGBp!u3Vk?=y sZg}sW{Yp28a7aeX9uxb%7 literal 0 HcmV?d00001 diff --git a/AppleWirelessKeyboard/CoreAudioAPI/AUDIO_VOLUME_NOTIFICATION_DATA.cs b/AppleWirelessKeyboard/CoreAudioAPI/AUDIO_VOLUME_NOTIFICATION_DATA.cs new file mode 100644 index 0000000..fe3319d --- /dev/null +++ b/AppleWirelessKeyboard/CoreAudioAPI/AUDIO_VOLUME_NOTIFICATION_DATA.cs @@ -0,0 +1,54 @@ +/* + LICENSE + ------- + Copyright (C) 2007-2010 Ray Molenkamp + + This source code is provided 'as-is', without any express or implied + warranty. In no event will the authors be held liable for any damages + arising from the use of this source code or the software it produces. + + Permission is granted to anyone to use this source code for any purpose, + including commercial applications, and to alter it and redistribute it + freely, subject to the following restrictions: + + 1. The origin of this source code must not be misrepresented; you must not + claim that you wrote the original source code. If you use this source code + in a product, an acknowledgment in the product documentation would be + appreciated but is not required. + 2. Altered source versions must be plainly marked as such, and must not be + misrepresented as being the original source code. + 3. This notice may not be removed or altered from any source distribution. +*/ + +using System; +using System.Collections.Generic; +using System.Text; + +namespace CoreAudioApi.Interfaces +{ + internal struct AUDIO_VOLUME_NOTIFICATION_DATA + { + public Guid guidEventContext; + public bool bMuted; + public float fMasterVolume; + public uint nChannels; + public float ChannelVolume; + + //Code Should Compile at warning level4 without any warnings, + //However this struct will give us Warning CS0649: Field [Fieldname] + //is never assigned to, and will always have its default value + //You can disable CS0649 in the project options but that will disable + //the warning for the whole project, it's a nice warning and we do want + //it in other places so we make a nice dummy function to keep the compiler + //happy. + private void FixCS0649() + { + guidEventContext = Guid.Empty; + bMuted = false; + fMasterVolume = 0; + nChannels = 0; + ChannelVolume = 0; + } + + } +} diff --git a/AppleWirelessKeyboard/CoreAudioAPI/AudioEndPointVolumeVolumeRange.cs b/AppleWirelessKeyboard/CoreAudioAPI/AudioEndPointVolumeVolumeRange.cs new file mode 100644 index 0000000..73dc0f4 --- /dev/null +++ b/AppleWirelessKeyboard/CoreAudioAPI/AudioEndPointVolumeVolumeRange.cs @@ -0,0 +1,65 @@ +/* + LICENSE + ------- + Copyright (C) 2007-2010 Ray Molenkamp + + This source code is provided 'as-is', without any express or implied + warranty. In no event will the authors be held liable for any damages + arising from the use of this source code or the software it produces. + + Permission is granted to anyone to use this source code for any purpose, + including commercial applications, and to alter it and redistribute it + freely, subject to the following restrictions: + + 1. The origin of this source code must not be misrepresented; you must not + claim that you wrote the original source code. If you use this source code + in a product, an acknowledgment in the product documentation would be + appreciated but is not required. + 2. Altered source versions must be plainly marked as such, and must not be + misrepresented as being the original source code. + 3. This notice may not be removed or altered from any source distribution. +*/ +using System; +using System.Collections.Generic; +using System.Text; +using CoreAudioApi.Interfaces; +using System.Runtime.InteropServices; + +namespace CoreAudioApi +{ + public class AudioEndPointVolumeVolumeRange + { + float _VolumeMindB; + float _VolumeMaxdB; + float _VolumeIncrementdB; + + internal AudioEndPointVolumeVolumeRange(IAudioEndpointVolume parent) + { + Marshal.ThrowExceptionForHR(parent.GetVolumeRange(out _VolumeMindB,out _VolumeMaxdB,out _VolumeIncrementdB)); + } + + public float MindB + { + get + { + return _VolumeMindB; + } + } + + public float MaxdB + { + get + { + return _VolumeMaxdB; + } + } + + public float IncrementdB + { + get + { + return _VolumeIncrementdB; + } + } + } +} diff --git a/AppleWirelessKeyboard/CoreAudioAPI/AudioEndpointVolume.cs b/AppleWirelessKeyboard/CoreAudioAPI/AudioEndpointVolume.cs new file mode 100644 index 0000000..2d2ce21 --- /dev/null +++ b/AppleWirelessKeyboard/CoreAudioAPI/AudioEndpointVolume.cs @@ -0,0 +1,157 @@ +/* + LICENSE + ------- + Copyright (C) 2007-2010 Ray Molenkamp + + This source code is provided 'as-is', without any express or implied + warranty. In no event will the authors be held liable for any damages + arising from the use of this source code or the software it produces. + + Permission is granted to anyone to use this source code for any purpose, + including commercial applications, and to alter it and redistribute it + freely, subject to the following restrictions: + + 1. The origin of this source code must not be misrepresented; you must not + claim that you wrote the original source code. If you use this source code + in a product, an acknowledgment in the product documentation would be + appreciated but is not required. + 2. Altered source versions must be plainly marked as such, and must not be + misrepresented as being the original source code. + 3. This notice may not be removed or altered from any source distribution. +*/ + +using System; +using System.Collections.Generic; +using System.Text; +using CoreAudioApi.Interfaces; +using System.Runtime.InteropServices; + +namespace CoreAudioApi +{ + + public class AudioEndpointVolume : IDisposable + { + private IAudioEndpointVolume _AudioEndPointVolume; + private AudioEndpointVolumeChannels _Channels; + private AudioEndpointVolumeStepInformation _StepInformation; + private AudioEndPointVolumeVolumeRange _VolumeRange; + private EEndpointHardwareSupport _HardwareSupport; + private AudioEndpointVolumeCallback _CallBack; + public event AudioEndpointVolumeNotificationDelegate OnVolumeNotification; + + public AudioEndPointVolumeVolumeRange VolumeRange + { + get + { + return _VolumeRange; + } + } + public EEndpointHardwareSupport HardwareSupport + { + get + { + return _HardwareSupport; + } + } + public AudioEndpointVolumeStepInformation StepInformation + { + get + { + return _StepInformation; + } + } + public AudioEndpointVolumeChannels Channels + { + get + { + return _Channels; + } + } + public float MasterVolumeLevel + { + get + { + float result; + Marshal.ThrowExceptionForHR(_AudioEndPointVolume.GetMasterVolumeLevel(out result)); + return result; + } + set + { + Marshal.ThrowExceptionForHR(_AudioEndPointVolume.SetMasterVolumeLevel(value, Guid.Empty)); + } + } + public float MasterVolumeLevelScalar + { + get + { + float result; + Marshal.ThrowExceptionForHR(_AudioEndPointVolume.GetMasterVolumeLevelScalar(out result)); + return result; + } + set + { + Marshal.ThrowExceptionForHR(_AudioEndPointVolume.SetMasterVolumeLevelScalar(value, Guid.Empty)); + } + } + public bool Mute + { + get + { + bool result; + Marshal.ThrowExceptionForHR(_AudioEndPointVolume.GetMute(out result)); + return result; + } + set + { + Marshal.ThrowExceptionForHR(_AudioEndPointVolume.SetMute(value, Guid.Empty)); + } + } + public void VolumeStepUp() + { + Marshal.ThrowExceptionForHR(_AudioEndPointVolume.VolumeStepUp(Guid.Empty)); + } + public void VolumeStepDown() + { + Marshal.ThrowExceptionForHR(_AudioEndPointVolume.VolumeStepDown(Guid.Empty)); + } + internal AudioEndpointVolume(IAudioEndpointVolume realEndpointVolume) + { + uint HardwareSupp; + + _AudioEndPointVolume = realEndpointVolume; + _Channels = new AudioEndpointVolumeChannels(_AudioEndPointVolume); + _StepInformation = new AudioEndpointVolumeStepInformation(_AudioEndPointVolume); + Marshal.ThrowExceptionForHR(_AudioEndPointVolume.QueryHardwareSupport(out HardwareSupp)); + _HardwareSupport = (EEndpointHardwareSupport)HardwareSupp; + _VolumeRange = new AudioEndPointVolumeVolumeRange(_AudioEndPointVolume); + _CallBack = new AudioEndpointVolumeCallback(this); + Marshal.ThrowExceptionForHR(_AudioEndPointVolume.RegisterControlChangeNotify( _CallBack)); + } + internal void FireNotification(AudioVolumeNotificationData NotificationData) + { + AudioEndpointVolumeNotificationDelegate del = OnVolumeNotification; + if (del != null) + { + del(NotificationData); + } + } + #region IDisposable Members + + public void Dispose() + { + if (_CallBack != null) + { + Marshal.ThrowExceptionForHR(_AudioEndPointVolume.UnregisterControlChangeNotify( _CallBack )); + _CallBack = null; + } + } + + ~AudioEndpointVolume() + { + Dispose(); + } + + #endregion + + } +} diff --git a/AppleWirelessKeyboard/CoreAudioAPI/AudioEndpointVolumeCallback.cs b/AppleWirelessKeyboard/CoreAudioAPI/AudioEndpointVolumeCallback.cs new file mode 100644 index 0000000..84de641 --- /dev/null +++ b/AppleWirelessKeyboard/CoreAudioAPI/AudioEndpointVolumeCallback.cs @@ -0,0 +1,73 @@ +/* + LICENSE + ------- + Copyright (C) 2007-2010 Ray Molenkamp + + This source code is provided 'as-is', without any express or implied + warranty. In no event will the authors be held liable for any damages + arising from the use of this source code or the software it produces. + + Permission is granted to anyone to use this source code for any purpose, + including commercial applications, and to alter it and redistribute it + freely, subject to the following restrictions: + + 1. The origin of this source code must not be misrepresented; you must not + claim that you wrote the original source code. If you use this source code + in a product, an acknowledgment in the product documentation would be + appreciated but is not required. + 2. Altered source versions must be plainly marked as such, and must not be + misrepresented as being the original source code. + 3. This notice may not be removed or altered from any source distribution. +*/ + +using System; +using System.Collections.Generic; +using System.Text; +using CoreAudioApi.Interfaces; +using System.Runtime.InteropServices; + +namespace CoreAudioApi +{ + // This class implements the IAudioEndpointVolumeCallback interface, + // it is implemented in this class because implementing it on AudioEndpointVolume + // (where the functionality is really wanted, would cause the OnNotify function + // to show up in the public API. + internal class AudioEndpointVolumeCallback : IAudioEndpointVolumeCallback + { + private AudioEndpointVolume _Parent; + + internal AudioEndpointVolumeCallback(AudioEndpointVolume parent) + { + _Parent = parent; + } + + [PreserveSig] public int OnNotify(IntPtr NotifyData) + { + //Since AUDIO_VOLUME_NOTIFICATION_DATA is dynamic in length based on the + //number of audio channels available we cannot just call PtrToStructure + //to get all data, thats why it is split up into two steps, first the static + //data is marshalled into the data structure, then with some IntPtr math the + //remaining floats are read from memory. + // + AUDIO_VOLUME_NOTIFICATION_DATA data = (AUDIO_VOLUME_NOTIFICATION_DATA) Marshal.PtrToStructure(NotifyData, typeof(AUDIO_VOLUME_NOTIFICATION_DATA)); + + //Determine offset in structure of the first float + IntPtr Offset = Marshal.OffsetOf(typeof(AUDIO_VOLUME_NOTIFICATION_DATA),"ChannelVolume"); + //Determine offset in memory of the first float + IntPtr FirstFloatPtr = (IntPtr)((long)NotifyData + (long)Offset); + + float[] voldata = new float[data.nChannels]; + + //Read all floats from memory. + for (int i = 0; i < data.nChannels; i++) + { + voldata[i] = (float)Marshal.PtrToStructure(FirstFloatPtr, typeof(float)); + } + + //Create combined structure and Fire Event in parent class. + AudioVolumeNotificationData NotificationData = new AudioVolumeNotificationData(data.guidEventContext, data.bMuted, data.fMasterVolume, voldata); + _Parent.FireNotification(NotificationData); + return 0; //S_OK + } + } +} diff --git a/AppleWirelessKeyboard/CoreAudioAPI/AudioEndpointVolumeChannel.cs b/AppleWirelessKeyboard/CoreAudioAPI/AudioEndpointVolumeChannel.cs new file mode 100644 index 0000000..ccead51 --- /dev/null +++ b/AppleWirelessKeyboard/CoreAudioAPI/AudioEndpointVolumeChannel.cs @@ -0,0 +1,71 @@ +/* + LICENSE + ------- + Copyright (C) 2007-2010 Ray Molenkamp + + This source code is provided 'as-is', without any express or implied + warranty. In no event will the authors be held liable for any damages + arising from the use of this source code or the software it produces. + + Permission is granted to anyone to use this source code for any purpose, + including commercial applications, and to alter it and redistribute it + freely, subject to the following restrictions: + + 1. The origin of this source code must not be misrepresented; you must not + claim that you wrote the original source code. If you use this source code + in a product, an acknowledgment in the product documentation would be + appreciated but is not required. + 2. Altered source versions must be plainly marked as such, and must not be + misrepresented as being the original source code. + 3. This notice may not be removed or altered from any source distribution. +*/ + +using System; +using System.Collections.Generic; +using System.Text; +using CoreAudioApi.Interfaces; +using System.Runtime.InteropServices; + +namespace CoreAudioApi +{ + public class AudioEndpointVolumeChannel + { + private uint _Channel; + private IAudioEndpointVolume _AudioEndpointVolume; + + internal AudioEndpointVolumeChannel(IAudioEndpointVolume parent, int channel) + { + _Channel = (uint)channel; + _AudioEndpointVolume = parent; + } + + public float VolumeLevel + { + get + { + float result; + Marshal.ThrowExceptionForHR(_AudioEndpointVolume.GetChannelVolumeLevel(_Channel,out result)); + return result; + } + set + { + Marshal.ThrowExceptionForHR(_AudioEndpointVolume.SetChannelVolumeLevel(_Channel, value,Guid.Empty)); + } + } + + public float VolumeLevelScalar + { + get + { + float result; + Marshal.ThrowExceptionForHR(_AudioEndpointVolume.GetChannelVolumeLevelScalar(_Channel, out result)); + return result; + } + set + { + Marshal.ThrowExceptionForHR(_AudioEndpointVolume.SetChannelVolumeLevelScalar(_Channel, value, Guid.Empty)); + } + } + + } +} diff --git a/AppleWirelessKeyboard/CoreAudioAPI/AudioEndpointVolumeChannels.cs b/AppleWirelessKeyboard/CoreAudioAPI/AudioEndpointVolumeChannels.cs new file mode 100644 index 0000000..5c6ce82 --- /dev/null +++ b/AppleWirelessKeyboard/CoreAudioAPI/AudioEndpointVolumeChannels.cs @@ -0,0 +1,68 @@ +/* + LICENSE + ------- + Copyright (C) 2007-2010 Ray Molenkamp + + This source code is provided 'as-is', without any express or implied + warranty. In no event will the authors be held liable for any damages + arising from the use of this source code or the software it produces. + + Permission is granted to anyone to use this source code for any purpose, + including commercial applications, and to alter it and redistribute it + freely, subject to the following restrictions: + + 1. The origin of this source code must not be misrepresented; you must not + claim that you wrote the original source code. If you use this source code + in a product, an acknowledgment in the product documentation would be + appreciated but is not required. + 2. Altered source versions must be plainly marked as such, and must not be + misrepresented as being the original source code. + 3. This notice may not be removed or altered from any source distribution. +*/ + +using System; +using System.Collections.Generic; +using System.Text; +using CoreAudioApi.Interfaces; +using System.Runtime.InteropServices; + +namespace CoreAudioApi +{ + public class AudioEndpointVolumeChannels + { + IAudioEndpointVolume _AudioEndPointVolume; + AudioEndpointVolumeChannel[] _Channels; + public int Count + { + get + { + int result; + Marshal.ThrowExceptionForHR(_AudioEndPointVolume.GetChannelCount(out result)); + return result; + } + } + + public AudioEndpointVolumeChannel this[int index] + { + get + { + return _Channels[index]; + } + } + + internal AudioEndpointVolumeChannels(IAudioEndpointVolume parent) + { + int ChannelCount; + _AudioEndPointVolume = parent; + + ChannelCount = Count; + _Channels = new AudioEndpointVolumeChannel[ChannelCount]; + for (int i = 0; i < ChannelCount; i++) + { + _Channels[i] = new AudioEndpointVolumeChannel(_AudioEndPointVolume, i); + } + } + + + } +} diff --git a/AppleWirelessKeyboard/CoreAudioAPI/AudioEndpointVolumeNotificationDelegate.cs b/AppleWirelessKeyboard/CoreAudioAPI/AudioEndpointVolumeNotificationDelegate.cs new file mode 100644 index 0000000..4d97c4b --- /dev/null +++ b/AppleWirelessKeyboard/CoreAudioAPI/AudioEndpointVolumeNotificationDelegate.cs @@ -0,0 +1,30 @@ +/* + LICENSE + ------- + Copyright (C) 2007-2010 Ray Molenkamp + + This source code is provided 'as-is', without any express or implied + warranty. In no event will the authors be held liable for any damages + arising from the use of this source code or the software it produces. + + Permission is granted to anyone to use this source code for any purpose, + including commercial applications, and to alter it and redistribute it + freely, subject to the following restrictions: + + 1. The origin of this source code must not be misrepresented; you must not + claim that you wrote the original source code. If you use this source code + in a product, an acknowledgment in the product documentation would be + appreciated but is not required. + 2. Altered source versions must be plainly marked as such, and must not be + misrepresented as being the original source code. + 3. This notice may not be removed or altered from any source distribution. +*/ + +using System; +using System.Collections.Generic; +using System.Text; + +namespace CoreAudioApi +{ + public delegate void AudioEndpointVolumeNotificationDelegate( AudioVolumeNotificationData data); +} diff --git a/AppleWirelessKeyboard/CoreAudioAPI/AudioEndpointVolumeStepInformation.cs b/AppleWirelessKeyboard/CoreAudioAPI/AudioEndpointVolumeStepInformation.cs new file mode 100644 index 0000000..bb77826 --- /dev/null +++ b/AppleWirelessKeyboard/CoreAudioAPI/AudioEndpointVolumeStepInformation.cs @@ -0,0 +1,56 @@ +/* + LICENSE + ------- + Copyright (C) 2007-2010 Ray Molenkamp + + This source code is provided 'as-is', without any express or implied + warranty. In no event will the authors be held liable for any damages + arising from the use of this source code or the software it produces. + + Permission is granted to anyone to use this source code for any purpose, + including commercial applications, and to alter it and redistribute it + freely, subject to the following restrictions: + + 1. The origin of this source code must not be misrepresented; you must not + claim that you wrote the original source code. If you use this source code + in a product, an acknowledgment in the product documentation would be + appreciated but is not required. + 2. Altered source versions must be plainly marked as such, and must not be + misrepresented as being the original source code. + 3. This notice may not be removed or altered from any source distribution. +*/ +using System; +using System.Collections.Generic; +using System.Text; +using CoreAudioApi.Interfaces; +using System.Runtime.InteropServices; + +namespace CoreAudioApi +{ + public class AudioEndpointVolumeStepInformation + { + private uint _Step; + private uint _StepCount; + internal AudioEndpointVolumeStepInformation(IAudioEndpointVolume parent) + { + Marshal.ThrowExceptionForHR(parent.GetVolumeStepInfo(out _Step, out _StepCount)); + } + + public uint Step + { + get + { + return _Step; + } + } + + public uint StepCount + { + get + { + return _StepCount; + } + } + + } +} diff --git a/AppleWirelessKeyboard/CoreAudioAPI/AudioMeterInformation.cs b/AppleWirelessKeyboard/CoreAudioAPI/AudioMeterInformation.cs new file mode 100644 index 0000000..1294f9e --- /dev/null +++ b/AppleWirelessKeyboard/CoreAudioAPI/AudioMeterInformation.cs @@ -0,0 +1,79 @@ +/* + LICENSE + ------- + Copyright (C) 2007-2010 Ray Molenkamp + + This source code is provided 'as-is', without any express or implied + warranty. In no event will the authors be held liable for any damages + arising from the use of this source code or the software it produces. + + Permission is granted to anyone to use this source code for any purpose, + including commercial applications, and to alter it and redistribute it + freely, subject to the following restrictions: + + 1. The origin of this source code must not be misrepresented; you must not + claim that you wrote the original source code. If you use this source code + in a product, an acknowledgment in the product documentation would be + appreciated but is not required. + 2. Altered source versions must be plainly marked as such, and must not be + misrepresented as being the original source code. + 3. This notice may not be removed or altered from any source distribution. +*/ +using System; +using System.Collections.Generic; +using System.Text; +using CoreAudioApi.Interfaces; +using System.Runtime.InteropServices; + +namespace CoreAudioApi +{ + public class AudioMeterInformation + { + private IAudioMeterInformation _AudioMeterInformation; + private EEndpointHardwareSupport _HardwareSupport; + private AudioMeterInformationChannels _Channels; + + internal AudioMeterInformation(IAudioMeterInformation realInterface) + { + int HardwareSupp; + + _AudioMeterInformation = realInterface; + Marshal.ThrowExceptionForHR(_AudioMeterInformation.QueryHardwareSupport(out HardwareSupp)); + _HardwareSupport = (EEndpointHardwareSupport)HardwareSupp; + _Channels = new AudioMeterInformationChannels(_AudioMeterInformation); + + } + + public AudioMeterInformationChannels PeakValues + { + get + { + return _Channels; + } + } + + public EEndpointHardwareSupport HardwareSupport + { + get + { + return _HardwareSupport; + } + } + + public float MasterPeakValue + { + get + { + float result; + Marshal.ThrowExceptionForHR(_AudioMeterInformation.GetPeakValue(out result)); + return result; + } + } + + + + + + + } +} diff --git a/AppleWirelessKeyboard/CoreAudioAPI/AudioMeterInformationChannels.cs b/AppleWirelessKeyboard/CoreAudioAPI/AudioMeterInformationChannels.cs new file mode 100644 index 0000000..3f9f0c8 --- /dev/null +++ b/AppleWirelessKeyboard/CoreAudioAPI/AudioMeterInformationChannels.cs @@ -0,0 +1,61 @@ +/* + LICENSE + ------- + Copyright (C) 2007-2010 Ray Molenkamp + + This source code is provided 'as-is', without any express or implied + warranty. In no event will the authors be held liable for any damages + arising from the use of this source code or the software it produces. + + Permission is granted to anyone to use this source code for any purpose, + including commercial applications, and to alter it and redistribute it + freely, subject to the following restrictions: + + 1. The origin of this source code must not be misrepresented; you must not + claim that you wrote the original source code. If you use this source code + in a product, an acknowledgment in the product documentation would be + appreciated but is not required. + 2. Altered source versions must be plainly marked as such, and must not be + misrepresented as being the original source code. + 3. This notice may not be removed or altered from any source distribution. +*/ +using System; +using System.Collections.Generic; +using System.Text; +using CoreAudioApi.Interfaces; +using System.Runtime.InteropServices; + +namespace CoreAudioApi +{ + public class AudioMeterInformationChannels + { + IAudioMeterInformation _AudioMeterInformation; + + public int Count + { + get + { + int result; + Marshal.ThrowExceptionForHR(_AudioMeterInformation.GetMeteringChannelCount(out result)); + return result; + } + } + + public float this[int index] + { + get + { + float[] peakValues = new float[Count]; + GCHandle Params = GCHandle.Alloc(peakValues, GCHandleType.Pinned); + Marshal.ThrowExceptionForHR(_AudioMeterInformation.GetChannelsPeakValues(peakValues.Length, Params.AddrOfPinnedObject())); + Params.Free(); + return peakValues[index]; + } + } + + internal AudioMeterInformationChannels(IAudioMeterInformation parent) + { + _AudioMeterInformation = parent; + } + } +} diff --git a/AppleWirelessKeyboard/CoreAudioAPI/AudioSessionControl.cs b/AppleWirelessKeyboard/CoreAudioAPI/AudioSessionControl.cs new file mode 100644 index 0000000..51a7366 --- /dev/null +++ b/AppleWirelessKeyboard/CoreAudioAPI/AudioSessionControl.cs @@ -0,0 +1,155 @@ +/* + LICENSE + ------- + Copyright (C) 2007-2010 Ray Molenkamp + + This source code is provided 'as-is', without any express or implied + warranty. In no event will the authors be held liable for any damages + arising from the use of this source code or the software it produces. + + Permission is granted to anyone to use this source code for any purpose, + including commercial applications, and to alter it and redistribute it + freely, subject to the following restrictions: + + 1. The origin of this source code must not be misrepresented; you must not + claim that you wrote the original source code. If you use this source code + in a product, an acknowledgment in the product documentation would be + appreciated but is not required. + 2. Altered source versions must be plainly marked as such, and must not be + misrepresented as being the original source code. + 3. This notice may not be removed or altered from any source distribution. +*/ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using CoreAudioApi.Interfaces; +using System.Runtime.InteropServices; + +namespace CoreAudioApi +{ + public class AudioSessionControl + { + internal IAudioSessionControl2 _AudioSessionControl; + internal AudioMeterInformation _AudioMeterInformation; + internal SimpleAudioVolume _SimpleAudioVolume; + + public AudioMeterInformation AudioMeterInformation + { + get + { + return _AudioMeterInformation; + } + } + + public SimpleAudioVolume SimpleAudioVolume + { + get + { + return _SimpleAudioVolume; + } + } + + + internal AudioSessionControl(IAudioSessionControl2 realAudioSessionControl) + { + IAudioMeterInformation _meters = realAudioSessionControl as IAudioMeterInformation; + ISimpleAudioVolume _volume = realAudioSessionControl as ISimpleAudioVolume; + if (_meters != null) + _AudioMeterInformation = new CoreAudioApi.AudioMeterInformation(_meters); + if (_volume != null) + _SimpleAudioVolume = new SimpleAudioVolume(_volume); + _AudioSessionControl = realAudioSessionControl; + + } + + public void RegisterAudioSessionNotification(IAudioSessionEvents eventConsumer) + { + Marshal.ThrowExceptionForHR(_AudioSessionControl.RegisterAudioSessionNotification(eventConsumer)); + } + + public void UnregisterAudioSessionNotification(IAudioSessionEvents eventConsumer) + { + Marshal.ThrowExceptionForHR(_AudioSessionControl.UnregisterAudioSessionNotification(eventConsumer)); + } + + public AudioSessionState State + { + get + { + AudioSessionState res; + Marshal.ThrowExceptionForHR(_AudioSessionControl.GetState(out res)); + return res; + } + } + + public string DisplayName + { + get + { + IntPtr NamePtr; + Marshal.ThrowExceptionForHR(_AudioSessionControl.GetDisplayName(out NamePtr)); + string res = Marshal.PtrToStringAuto(NamePtr); + Marshal.FreeCoTaskMem(NamePtr); + return res; + } + } + + public string IconPath + { + get + { + IntPtr NamePtr; + Marshal.ThrowExceptionForHR(_AudioSessionControl.GetIconPath(out NamePtr)); + string res = Marshal.PtrToStringAuto(NamePtr); + Marshal.FreeCoTaskMem(NamePtr); + return res; + } + } + + public string SessionIdentifier + { + get + { + IntPtr NamePtr; + Marshal.ThrowExceptionForHR(_AudioSessionControl.GetSessionIdentifier(out NamePtr)); + string res = Marshal.PtrToStringAuto(NamePtr); + Marshal.FreeCoTaskMem(NamePtr); + return res; + } + } + + public string SessionInstanceIdentifier + { + get + { + IntPtr NamePtr; + Marshal.ThrowExceptionForHR(_AudioSessionControl.GetSessionInstanceIdentifier(out NamePtr)); + string res = Marshal.PtrToStringAuto(NamePtr); + Marshal.FreeCoTaskMem(NamePtr); + return res; + } + } + + public uint ProcessID + { + get + { + uint pid; + Marshal.ThrowExceptionForHR(_AudioSessionControl.GetProcessId(out pid)); + return pid; + } + } + + public bool IsSystemIsSystemSoundsSession + { + get + { + return (_AudioSessionControl.IsSystemSoundsSession() == 0); //S_OK + } + + } + + + } +} diff --git a/AppleWirelessKeyboard/CoreAudioAPI/AudioSessionDisconnectReason.cs b/AppleWirelessKeyboard/CoreAudioAPI/AudioSessionDisconnectReason.cs new file mode 100644 index 0000000..3f4735f --- /dev/null +++ b/AppleWirelessKeyboard/CoreAudioAPI/AudioSessionDisconnectReason.cs @@ -0,0 +1,38 @@ +/* + LICENSE + ------- + Copyright (C) 2007-2010 Ray Molenkamp + + This source code is provided 'as-is', without any express or implied + warranty. In no event will the authors be held liable for any damages + arising from the use of this source code or the software it produces. + + Permission is granted to anyone to use this source code for any purpose, + including commercial applications, and to alter it and redistribute it + freely, subject to the following restrictions: + + 1. The origin of this source code must not be misrepresented; you must not + claim that you wrote the original source code. If you use this source code + in a product, an acknowledgment in the product documentation would be + appreciated but is not required. + 2. Altered source versions must be plainly marked as such, and must not be + misrepresented as being the original source code. + 3. This notice may not be removed or altered from any source distribution. +*/ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace CoreAudioApi +{ + public enum AudioSessionDisconnectReason + { + DisconnectReasonDeviceRemoval = 0, + DisconnectReasonServerShutdown = (DisconnectReasonDeviceRemoval + 1), + DisconnectReasonFormatChanged = (DisconnectReasonServerShutdown + 1), + DisconnectReasonSessionLogoff = (DisconnectReasonFormatChanged + 1), + DisconnectReasonSessionDisconnected = (DisconnectReasonSessionLogoff + 1), + DisconnectReasonExclusiveModeOverride = (DisconnectReasonSessionDisconnected + 1) + } +} diff --git a/AppleWirelessKeyboard/CoreAudioAPI/AudioSessionManager.cs b/AppleWirelessKeyboard/CoreAudioAPI/AudioSessionManager.cs new file mode 100644 index 0000000..dccc1a3 --- /dev/null +++ b/AppleWirelessKeyboard/CoreAudioAPI/AudioSessionManager.cs @@ -0,0 +1,54 @@ +/* + LICENSE + ------- + Copyright (C) 2007-2010 Ray Molenkamp + + This source code is provided 'as-is', without any express or implied + warranty. In no event will the authors be held liable for any damages + arising from the use of this source code or the software it produces. + + Permission is granted to anyone to use this source code for any purpose, + including commercial applications, and to alter it and redistribute it + freely, subject to the following restrictions: + + 1. The origin of this source code must not be misrepresented; you must not + claim that you wrote the original source code. If you use this source code + in a product, an acknowledgment in the product documentation would be + appreciated but is not required. + 2. Altered source versions must be plainly marked as such, and must not be + misrepresented as being the original source code. + 3. This notice may not be removed or altered from any source distribution. +*/ + +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using CoreAudioApi.Interfaces; +using System.Runtime.InteropServices; + +namespace CoreAudioApi +{ + public class AudioSessionManager + { + private IAudioSessionManager2 _AudioSessionManager; + private SessionCollection _Sessions; + + internal AudioSessionManager(IAudioSessionManager2 realAudioSessionManager) + { + _AudioSessionManager = realAudioSessionManager; + IAudioSessionEnumerator _SessionEnum ; + Marshal.ThrowExceptionForHR(_AudioSessionManager.GetSessionEnumerator(out _SessionEnum)); + _Sessions = new SessionCollection(_SessionEnum); + } + + public SessionCollection Sessions + { + get + { + return _Sessions; + } + } + + } +} diff --git a/AppleWirelessKeyboard/CoreAudioAPI/AudioSessionState.cs b/AppleWirelessKeyboard/CoreAudioAPI/AudioSessionState.cs new file mode 100644 index 0000000..ce85fcc --- /dev/null +++ b/AppleWirelessKeyboard/CoreAudioAPI/AudioSessionState.cs @@ -0,0 +1,35 @@ +/* + LICENSE + ------- + Copyright (C) 2007-2010 Ray Molenkamp + + This source code is provided 'as-is', without any express or implied + warranty. In no event will the authors be held liable for any damages + arising from the use of this source code or the software it produces. + + Permission is granted to anyone to use this source code for any purpose, + including commercial applications, and to alter it and redistribute it + freely, subject to the following restrictions: + + 1. The origin of this source code must not be misrepresented; you must not + claim that you wrote the original source code. If you use this source code + in a product, an acknowledgment in the product documentation would be + appreciated but is not required. + 2. Altered source versions must be plainly marked as such, and must not be + misrepresented as being the original source code. + 3. This notice may not be removed or altered from any source distribution. +*/ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace CoreAudioApi +{ + public enum AudioSessionState + { + AudioSessionStateInactive = 0, + AudioSessionStateActive = 1, + AudioSessionStateExpired = 2 + } +} diff --git a/AppleWirelessKeyboard/CoreAudioAPI/AudioVolumeNotificationData.cs b/AppleWirelessKeyboard/CoreAudioAPI/AudioVolumeNotificationData.cs new file mode 100644 index 0000000..cb18edf --- /dev/null +++ b/AppleWirelessKeyboard/CoreAudioAPI/AudioVolumeNotificationData.cs @@ -0,0 +1,83 @@ +/* + LICENSE + ------- + Copyright (C) 2007-2010 Ray Molenkamp + + This source code is provided 'as-is', without any express or implied + warranty. In no event will the authors be held liable for any damages + arising from the use of this source code or the software it produces. + + Permission is granted to anyone to use this source code for any purpose, + including commercial applications, and to alter it and redistribute it + freely, subject to the following restrictions: + + 1. The origin of this source code must not be misrepresented; you must not + claim that you wrote the original source code. If you use this source code + in a product, an acknowledgment in the product documentation would be + appreciated but is not required. + 2. Altered source versions must be plainly marked as such, and must not be + misrepresented as being the original source code. + 3. This notice may not be removed or altered from any source distribution. +*/ +using System; +using System.Collections.Generic; +using System.Text; + +namespace CoreAudioApi +{ + public class AudioVolumeNotificationData + { + private Guid _EventContext; + private bool _Muted; + private float _MasterVolume; + private int _Channels; + private float[] _ChannelVolume; + + public Guid EventContext + { + get + { + return _EventContext; + } + } + + public bool Muted + { + get + { + return _Muted; + } + } + + public float MasterVolume + { + get + { + return _MasterVolume; + } + } + public int Channels + { + get + { + return _Channels; + } + } + + public float[] ChannelVolume + { + get + { + return _ChannelVolume; + } + } + public AudioVolumeNotificationData(Guid eventContext, bool muted, float masterVolume, float[] channelVolume) + { + _EventContext = eventContext; + _Muted = muted; + _MasterVolume = masterVolume; + _Channels = channelVolume.Length; + _ChannelVolume = channelVolume; + } + } +} diff --git a/AppleWirelessKeyboard/CoreAudioAPI/Blob.cs b/AppleWirelessKeyboard/CoreAudioAPI/Blob.cs new file mode 100644 index 0000000..99ab275 --- /dev/null +++ b/AppleWirelessKeyboard/CoreAudioAPI/Blob.cs @@ -0,0 +1,47 @@ +/* + LICENSE + ------- + Copyright (C) 2007-2010 Ray Molenkamp + + This source code is provided 'as-is', without any express or implied + warranty. In no event will the authors be held liable for any damages + arising from the use of this source code or the software it produces. + + Permission is granted to anyone to use this source code for any purpose, + including commercial applications, and to alter it and redistribute it + freely, subject to the following restrictions: + + 1. The origin of this source code must not be misrepresented; you must not + claim that you wrote the original source code. If you use this source code + in a product, an acknowledgment in the product documentation would be + appreciated but is not required. + 2. Altered source versions must be plainly marked as such, and must not be + misrepresented as being the original source code. + 3. This notice may not be removed or altered from any source distribution. +*/ +using System; +using System.Collections.Generic; +using System.Text; +using System.Runtime.InteropServices; + +namespace CoreAudioApi.Interfaces +{ + internal struct Blob + { + public int Length; + public IntPtr Data; + + //Code Should Compile at warning level4 without any warnings, + //However this struct will give us Warning CS0649: Field [Fieldname] + //is never assigned to, and will always have its default value + //You can disable CS0649 in the project options but that will disable + //the warning for the whole project, it's a nice warning and we do want + //it in other places so we make a nice dummy function to keep the compiler + //happy. + private void FixCS0649() + { + Length = 0; + Data = IntPtr.Zero; + } + } +} diff --git a/AppleWirelessKeyboard/CoreAudioAPI/CLSCTX.cs b/AppleWirelessKeyboard/CoreAudioAPI/CLSCTX.cs new file mode 100644 index 0000000..9a3352f --- /dev/null +++ b/AppleWirelessKeyboard/CoreAudioAPI/CLSCTX.cs @@ -0,0 +1,53 @@ +/* + LICENSE + ------- + Copyright (C) 2007-2010 Ray Molenkamp + + This source code is provided 'as-is', without any express or implied + warranty. In no event will the authors be held liable for any damages + arising from the use of this source code or the software it produces. + + Permission is granted to anyone to use this source code for any purpose, + including commercial applications, and to alter it and redistribute it + freely, subject to the following restrictions: + + 1. The origin of this source code must not be misrepresented; you must not + claim that you wrote the original source code. If you use this source code + in a product, an acknowledgment in the product documentation would be + appreciated but is not required. + 2. Altered source versions must be plainly marked as such, and must not be + misrepresented as being the original source code. + 3. This notice may not be removed or altered from any source distribution. +*/ +using System; +using System.Collections.Generic; +using System.Text; + +namespace CoreAudioApi.Interfaces +{ + [Flags] + internal enum CLSCTX : uint + { + INPROC_SERVER = 0x1, + INPROC_HANDLER = 0x2, + LOCAL_SERVER = 0x4, + INPROC_SERVER16 = 0x8, + REMOTE_SERVER = 0x10, + INPROC_HANDLER16 = 0x20, + RESERVED1 = 0x40, + RESERVED2 = 0x80, + RESERVED3 = 0x100, + RESERVED4 = 0x200, + NO_CODE_DOWNLOAD = 0x400, + RESERVED5 = 0x800, + NO_CUSTOM_MARSHAL = 0x1000, + ENABLE_CODE_DOWNLOAD = 0x2000, + NO_FAILURE_LOG = 0x4000, + DISABLE_AAA = 0x8000, + ENABLE_AAA = 0x10000, + FROM_DEFAULT_CONTEXT = 0x20000, + INPROC = INPROC_SERVER | INPROC_HANDLER, + SERVER = INPROC_SERVER | LOCAL_SERVER | REMOTE_SERVER, + ALL = SERVER | INPROC_HANDLER + } +} diff --git a/AppleWirelessKeyboard/CoreAudioAPI/EDataFlow.cs b/AppleWirelessKeyboard/CoreAudioAPI/EDataFlow.cs new file mode 100644 index 0000000..b43aa0d --- /dev/null +++ b/AppleWirelessKeyboard/CoreAudioAPI/EDataFlow.cs @@ -0,0 +1,35 @@ +/* + LICENSE + ------- + Copyright (C) 2007-2010 Ray Molenkamp + + This source code is provided 'as-is', without any express or implied + warranty. In no event will the authors be held liable for any damages + arising from the use of this source code or the software it produces. + + Permission is granted to anyone to use this source code for any purpose, + including commercial applications, and to alter it and redistribute it + freely, subject to the following restrictions: + + 1. The origin of this source code must not be misrepresented; you must not + claim that you wrote the original source code. If you use this source code + in a product, an acknowledgment in the product documentation would be + appreciated but is not required. + 2. Altered source versions must be plainly marked as such, and must not be + misrepresented as being the original source code. + 3. This notice may not be removed or altered from any source distribution. +*/ +using System; +using System.Collections.Generic; +using System.Text; + +namespace CoreAudioApi +{ + public enum EDataFlow + { + eRender = 0, + eCapture = 1, + eAll = 2 , + EDataFlow_enum_count =3 + } +} diff --git a/AppleWirelessKeyboard/CoreAudioAPI/EDeviceState.cs b/AppleWirelessKeyboard/CoreAudioAPI/EDeviceState.cs new file mode 100644 index 0000000..4b8b02e --- /dev/null +++ b/AppleWirelessKeyboard/CoreAudioAPI/EDeviceState.cs @@ -0,0 +1,36 @@ +/* + LICENSE + ------- + Copyright (C) 2007-2010 Ray Molenkamp + + This source code is provided 'as-is', without any express or implied + warranty. In no event will the authors be held liable for any damages + arising from the use of this source code or the software it produces. + + Permission is granted to anyone to use this source code for any purpose, + including commercial applications, and to alter it and redistribute it + freely, subject to the following restrictions: + + 1. The origin of this source code must not be misrepresented; you must not + claim that you wrote the original source code. If you use this source code + in a product, an acknowledgment in the product documentation would be + appreciated but is not required. + 2. Altered source versions must be plainly marked as such, and must not be + misrepresented as being the original source code. + 3. This notice may not be removed or altered from any source distribution. +*/ +using System; +using System.Collections.Generic; +using System.Text; + +namespace CoreAudioApi +{ + [Flags] + public enum EDeviceState : uint + { + DEVICE_STATE_ACTIVE = 0x00000001, + DEVICE_STATE_UNPLUGGED = 0x00000002, + DEVICE_STATE_NOTPRESENT = 0x00000004, + DEVICE_STATEMASK_ALL = 0x00000007 + } +} diff --git a/AppleWirelessKeyboard/CoreAudioAPI/EEndpointHardwareSupport.cs b/AppleWirelessKeyboard/CoreAudioAPI/EEndpointHardwareSupport.cs new file mode 100644 index 0000000..a394b43 --- /dev/null +++ b/AppleWirelessKeyboard/CoreAudioAPI/EEndpointHardwareSupport.cs @@ -0,0 +1,35 @@ +/* + LICENSE + ------- + Copyright (C) 2007-2010 Ray Molenkamp + + This source code is provided 'as-is', without any express or implied + warranty. In no event will the authors be held liable for any damages + arising from the use of this source code or the software it produces. + + Permission is granted to anyone to use this source code for any purpose, + including commercial applications, and to alter it and redistribute it + freely, subject to the following restrictions: + + 1. The origin of this source code must not be misrepresented; you must not + claim that you wrote the original source code. If you use this source code + in a product, an acknowledgment in the product documentation would be + appreciated but is not required. + 2. Altered source versions must be plainly marked as such, and must not be + misrepresented as being the original source code. + 3. This notice may not be removed or altered from any source distribution. +*/ +using System; +using System.Collections.Generic; +using System.Text; + +namespace CoreAudioApi +{ + [Flags] + public enum EEndpointHardwareSupport + { + Volume = 0x00000001, + Mute = 0x00000002, + Meter = 0x00000004 + } +} diff --git a/AppleWirelessKeyboard/CoreAudioAPI/ERole.cs b/AppleWirelessKeyboard/CoreAudioAPI/ERole.cs new file mode 100644 index 0000000..b19973b --- /dev/null +++ b/AppleWirelessKeyboard/CoreAudioAPI/ERole.cs @@ -0,0 +1,35 @@ +/* + LICENSE + ------- + Copyright (C) 2007-2010 Ray Molenkamp + + This source code is provided 'as-is', without any express or implied + warranty. In no event will the authors be held liable for any damages + arising from the use of this source code or the software it produces. + + Permission is granted to anyone to use this source code for any purpose, + including commercial applications, and to alter it and redistribute it + freely, subject to the following restrictions: + + 1. The origin of this source code must not be misrepresented; you must not + claim that you wrote the original source code. If you use this source code + in a product, an acknowledgment in the product documentation would be + appreciated but is not required. + 2. Altered source versions must be plainly marked as such, and must not be + misrepresented as being the original source code. + 3. This notice may not be removed or altered from any source distribution. +*/ +using System; +using System.Collections.Generic; +using System.Text; + +namespace CoreAudioApi +{ + public enum ERole + { + eConsole =0, + eMultimedia =1, + eCommunications=2, + ERole_enum_count=3 + } +} diff --git a/AppleWirelessKeyboard/CoreAudioAPI/IAudioEndpointVolume.cs b/AppleWirelessKeyboard/CoreAudioAPI/IAudioEndpointVolume.cs new file mode 100644 index 0000000..2af5c13 --- /dev/null +++ b/AppleWirelessKeyboard/CoreAudioAPI/IAudioEndpointVolume.cs @@ -0,0 +1,70 @@ +/* + LICENSE + ------- + Copyright (C) 2007-2010 Ray Molenkamp + + This source code is provided 'as-is', without any express or implied + warranty. In no event will the authors be held liable for any damages + arising from the use of this source code or the software it produces. + + Permission is granted to anyone to use this source code for any purpose, + including commercial applications, and to alter it and redistribute it + freely, subject to the following restrictions: + + 1. The origin of this source code must not be misrepresented; you must not + claim that you wrote the original source code. If you use this source code + in a product, an acknowledgment in the product documentation would be + appreciated but is not required. + 2. Altered source versions must be plainly marked as such, and must not be + misrepresented as being the original source code. + 3. This notice may not be removed or altered from any source distribution. +*/ +using System; +using System.Collections.Generic; +using System.Text; +using System.Runtime.InteropServices; + +namespace CoreAudioApi.Interfaces +{ + [Guid("5CDF2C82-841E-4546-9722-0CF74078229A"), + InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] + internal interface IAudioEndpointVolume + { + [PreserveSig] + int RegisterControlChangeNotify(IAudioEndpointVolumeCallback pNotify); + [PreserveSig] + int UnregisterControlChangeNotify(IAudioEndpointVolumeCallback pNotify); + [PreserveSig] + int GetChannelCount(out int pnChannelCount); + [PreserveSig] + int SetMasterVolumeLevel(float fLevelDB, Guid pguidEventContext); + [PreserveSig] + int SetMasterVolumeLevelScalar(float fLevel, Guid pguidEventContext); + [PreserveSig] + int GetMasterVolumeLevel(out float pfLevelDB); + [PreserveSig] + int GetMasterVolumeLevelScalar(out float pfLevel); + [PreserveSig] + int SetChannelVolumeLevel(uint nChannel, float fLevelDB, Guid pguidEventContext); + [PreserveSig] + int SetChannelVolumeLevelScalar(uint nChannel, float fLevel, Guid pguidEventContext); + [PreserveSig] + int GetChannelVolumeLevel(uint nChannel, out float pfLevelDB); + [PreserveSig] + int GetChannelVolumeLevelScalar(uint nChannel, out float pfLevel); + [PreserveSig] + int SetMute([MarshalAs(UnmanagedType.Bool)] Boolean bMute, Guid pguidEventContext); + [PreserveSig] + int GetMute(out bool pbMute); + [PreserveSig] + int GetVolumeStepInfo(out uint pnStep, out uint pnStepCount); + [PreserveSig] + int VolumeStepUp(Guid pguidEventContext); + [PreserveSig] + int VolumeStepDown(Guid pguidEventContext); + [PreserveSig] + int QueryHardwareSupport(out uint pdwHardwareSupportMask); + [PreserveSig] + int GetVolumeRange(out float pflVolumeMindB, out float pflVolumeMaxdB, out float pflVolumeIncrementdB); + } +} diff --git a/AppleWirelessKeyboard/CoreAudioAPI/IAudioEndpointVolumeCallback.cs b/AppleWirelessKeyboard/CoreAudioAPI/IAudioEndpointVolumeCallback.cs new file mode 100644 index 0000000..50e8fe9 --- /dev/null +++ b/AppleWirelessKeyboard/CoreAudioAPI/IAudioEndpointVolumeCallback.cs @@ -0,0 +1,36 @@ +/* + LICENSE + ------- + Copyright (C) 2007-2010 Ray Molenkamp + + This source code is provided 'as-is', without any express or implied + warranty. In no event will the authors be held liable for any damages + arising from the use of this source code or the software it produces. + + Permission is granted to anyone to use this source code for any purpose, + including commercial applications, and to alter it and redistribute it + freely, subject to the following restrictions: + + 1. The origin of this source code must not be misrepresented; you must not + claim that you wrote the original source code. If you use this source code + in a product, an acknowledgment in the product documentation would be + appreciated but is not required. + 2. Altered source versions must be plainly marked as such, and must not be + misrepresented as being the original source code. + 3. This notice may not be removed or altered from any source distribution. +*/ +using System; +using System.Collections.Generic; +using System.Text; +using System.Runtime.InteropServices; + +namespace CoreAudioApi.Interfaces +{ + [Guid("657804FA-D6AD-4496-8A60-352752AF4F89"), + InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] + internal interface IAudioEndpointVolumeCallback + { + [PreserveSig] int OnNotify(IntPtr pNotifyData); + }; + +} diff --git a/AppleWirelessKeyboard/CoreAudioAPI/IAudioMeterInformation.cs b/AppleWirelessKeyboard/CoreAudioAPI/IAudioMeterInformation.cs new file mode 100644 index 0000000..37a7ae3 --- /dev/null +++ b/AppleWirelessKeyboard/CoreAudioAPI/IAudioMeterInformation.cs @@ -0,0 +1,42 @@ +/* + LICENSE + ------- + Copyright (C) 2007-2010 Ray Molenkamp + + This source code is provided 'as-is', without any express or implied + warranty. In no event will the authors be held liable for any damages + arising from the use of this source code or the software it produces. + + Permission is granted to anyone to use this source code for any purpose, + including commercial applications, and to alter it and redistribute it + freely, subject to the following restrictions: + + 1. The origin of this source code must not be misrepresented; you must not + claim that you wrote the original source code. If you use this source code + in a product, an acknowledgment in the product documentation would be + appreciated but is not required. + 2. Altered source versions must be plainly marked as such, and must not be + misrepresented as being the original source code. + 3. This notice may not be removed or altered from any source distribution. +*/ +using System; +using System.Collections.Generic; +using System.Text; +using System.Runtime.InteropServices; + +namespace CoreAudioApi.Interfaces +{ + [Guid("C02216F6-8C67-4B5B-9D00-D008E73E0064"), + InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] + internal interface IAudioMeterInformation + { + [PreserveSig] + int GetPeakValue(out float pfPeak); + [PreserveSig] + int GetMeteringChannelCount(out int pnChannelCount); + [PreserveSig] + int GetChannelsPeakValues( int u32ChannelCount,[In] IntPtr afPeakValues); + [PreserveSig] + int QueryHardwareSupport( out int pdwHardwareSupportMask); + }; +} diff --git a/AppleWirelessKeyboard/CoreAudioAPI/IAudioPeakMeter.cs b/AppleWirelessKeyboard/CoreAudioAPI/IAudioPeakMeter.cs new file mode 100644 index 0000000..c2d402d --- /dev/null +++ b/AppleWirelessKeyboard/CoreAudioAPI/IAudioPeakMeter.cs @@ -0,0 +1,37 @@ +/* + LICENSE + ------- + Copyright (C) 2007-2010 Ray Molenkamp + + This source code is provided 'as-is', without any express or implied + warranty. In no event will the authors be held liable for any damages + arising from the use of this source code or the software it produces. + + Permission is granted to anyone to use this source code for any purpose, + including commercial applications, and to alter it and redistribute it + freely, subject to the following restrictions: + + 1. The origin of this source code must not be misrepresented; you must not + claim that you wrote the original source code. If you use this source code + in a product, an acknowledgment in the product documentation would be + appreciated but is not required. + 2. Altered source versions must be plainly marked as such, and must not be + misrepresented as being the original source code. + 3. This notice may not be removed or altered from any source distribution. +*/ +using System; +using System.Collections.Generic; +using System.Text; +using System.Runtime.InteropServices; + + +namespace CoreAudioApi.Interfaces +{ + [Guid("DD79923C-0599-45e0-B8B6-C8DF7DB6E796"), + InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] + internal interface IAudioPeakMeter + { + int GetChannelCount( out int pcChannels); + int GetLevel( int Channel, out float level); + } +} diff --git a/AppleWirelessKeyboard/CoreAudioAPI/IAudioSessionControl2.cs b/AppleWirelessKeyboard/CoreAudioAPI/IAudioSessionControl2.cs new file mode 100644 index 0000000..35ad8c3 --- /dev/null +++ b/AppleWirelessKeyboard/CoreAudioAPI/IAudioSessionControl2.cs @@ -0,0 +1,66 @@ +/* + LICENSE + ------- + Copyright (C) 2007-2010 Ray Molenkamp + + This source code is provided 'as-is', without any express or implied + warranty. In no event will the authors be held liable for any damages + arising from the use of this source code or the software it produces. + + Permission is granted to anyone to use this source code for any purpose, + including commercial applications, and to alter it and redistribute it + freely, subject to the following restrictions: + + 1. The origin of this source code must not be misrepresented; you must not + claim that you wrote the original source code. If you use this source code + in a product, an acknowledgment in the product documentation would be + appreciated but is not required. + 2. Altered source versions must be plainly marked as such, and must not be + misrepresented as being the original source code. + 3. This notice may not be removed or altered from any source distribution. +*/ +using System; +using System.Collections.Generic; +using System.Text; +using System.Runtime.InteropServices; + +namespace CoreAudioApi.Interfaces +{ + [Guid("bfb7ff88-7239-4fc9-8fa2-07c950be9c6d"), + InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] + interface IAudioSessionControl2 + { + //IAudioSession functions + [PreserveSig] + int GetState(out AudioSessionState state); + [PreserveSig] + int GetDisplayName(out IntPtr name); + [PreserveSig] + int SetDisplayName(string value, Guid EventContext); + [PreserveSig] + int GetIconPath(out IntPtr Path); + [PreserveSig] + int SetIconPath(string Value, Guid EventContext); + [PreserveSig] + int GetGroupingParam(out Guid GroupingParam); + [PreserveSig] + int SetGroupingParam(Guid Override, Guid Eventcontext); + [PreserveSig] + int RegisterAudioSessionNotification(IAudioSessionEvents NewNotifications); + [PreserveSig] + int UnregisterAudioSessionNotification(IAudioSessionEvents NewNotifications); + //IAudioSession2 functions + [PreserveSig] + int GetSessionIdentifier( out IntPtr retVal); + [PreserveSig] + int GetSessionInstanceIdentifier( out IntPtr retVal); + [PreserveSig] + int GetProcessId( out UInt32 retvVal); + [PreserveSig] + int IsSystemSoundsSession(); + [PreserveSig] + int SetDuckingPreference( bool optOut); + + + } +} diff --git a/AppleWirelessKeyboard/CoreAudioAPI/IAudioSessionEnumerator.cs b/AppleWirelessKeyboard/CoreAudioAPI/IAudioSessionEnumerator.cs new file mode 100644 index 0000000..9ab89fc --- /dev/null +++ b/AppleWirelessKeyboard/CoreAudioAPI/IAudioSessionEnumerator.cs @@ -0,0 +1,34 @@ +/* + LICENSE + ------- + Copyright (C) 2007-2010 Ray Molenkamp + + This source code is provided 'as-is', without any express or implied + warranty. In no event will the authors be held liable for any damages + arising from the use of this source code or the software it produces. + + Permission is granted to anyone to use this source code for any purpose, + including commercial applications, and to alter it and redistribute it + freely, subject to the following restrictions: + + 1. The origin of this source code must not be misrepresented; you must not + claim that you wrote the original source code. If you use this source code + in a product, an acknowledgment in the product documentation would be + appreciated but is not required. + 2. Altered source versions must be plainly marked as such, and must not be + misrepresented as being the original source code. + 3. This notice may not be removed or altered from any source distribution. +*/ + +using System.Runtime.InteropServices; +using System; +namespace CoreAudioApi.Interfaces +{ + [Guid("E2F5BB11-0570-40CA-ACDD-3AA01277DEE8"), + InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] + internal interface IAudioSessionEnumerator + { + int GetCount( out int SessionCount); + int GetSession( int SessionCount,out IAudioSessionControl2 Session ); + } +} diff --git a/AppleWirelessKeyboard/CoreAudioAPI/IAudioSessionEvents.cs b/AppleWirelessKeyboard/CoreAudioAPI/IAudioSessionEvents.cs new file mode 100644 index 0000000..a3335c0 --- /dev/null +++ b/AppleWirelessKeyboard/CoreAudioAPI/IAudioSessionEvents.cs @@ -0,0 +1,48 @@ +/* + LICENSE + ------- + Copyright (C) 2007-2010 Ray Molenkamp + + This source code is provided 'as-is', without any express or implied + warranty. In no event will the authors be held liable for any damages + arising from the use of this source code or the software it produces. + + Permission is granted to anyone to use this source code for any purpose, + including commercial applications, and to alter it and redistribute it + freely, subject to the following restrictions: + + 1. The origin of this source code must not be misrepresented; you must not + claim that you wrote the original source code. If you use this source code + in a product, an acknowledgment in the product documentation would be + appreciated but is not required. + 2. Altered source versions must be plainly marked as such, and must not be + misrepresented as being the original source code. + 3. This notice may not be removed or altered from any source distribution. +*/ +using System; +using System.Collections.Generic; +using System.Text; +using System.Runtime.InteropServices; + +namespace CoreAudioApi.Interfaces +{ + [Guid("24918ACC-64B3-37C1-8CA9-74A66E9957A8"), + InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] + public interface IAudioSessionEvents + { + [PreserveSig] + int OnDisplayNameChanged( [MarshalAs(UnmanagedType.LPWStr)] string NewDisplayName, Guid EventContext ); + [PreserveSig] + int OnIconPathChanged( [MarshalAs(UnmanagedType.LPWStr)] string NewIconPath, Guid EventContext ); + [PreserveSig] + int OnSimpleVolumeChanged( float NewVolume,bool newMute, Guid EventContext ); + [PreserveSig] + int OnChannelVolumeChanged( UInt32 ChannelCount, IntPtr NewChannelVolumeArray, UInt32 ChangedChannel, Guid EventContext ); + [PreserveSig] + int OnGroupingParamChanged( Guid NewGroupingParam, Guid EventContext ); + [PreserveSig] + int OnStateChanged( AudioSessionState NewState); + [PreserveSig] + int OnSessionDisconnected( AudioSessionDisconnectReason DisconnectReason); + } +} diff --git a/AppleWirelessKeyboard/CoreAudioAPI/IAudioSessionManager2.cs b/AppleWirelessKeyboard/CoreAudioAPI/IAudioSessionManager2.cs new file mode 100644 index 0000000..eb0d809 --- /dev/null +++ b/AppleWirelessKeyboard/CoreAudioAPI/IAudioSessionManager2.cs @@ -0,0 +1,49 @@ +/* + LICENSE + ------- + Copyright (C) 2007-2010 Ray Molenkamp + + This source code is provided 'as-is', without any express or implied + warranty. In no event will the authors be held liable for any damages + arising from the use of this source code or the software it produces. + + Permission is granted to anyone to use this source code for any purpose, + including commercial applications, and to alter it and redistribute it + freely, subject to the following restrictions: + + 1. The origin of this source code must not be misrepresented; you must not + claim that you wrote the original source code. If you use this source code + in a product, an acknowledgment in the product documentation would be + appreciated but is not required. + 2. Altered source versions must be plainly marked as such, and must not be + misrepresented as being the original source code. + 3. This notice may not be removed or altered from any source distribution. +*/ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Runtime.InteropServices; + +namespace CoreAudioApi.Interfaces +{ + [Guid("77AA99A0-1BD6-484F-8BC7-2C654C9A9B6F"), + InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] + interface IAudioSessionManager2 + { + [PreserveSig] + int GetAudioSessionControl(ref Guid AudioSessionGuid, UInt32 StreamFlags, IntPtr ISessionControl ); + [PreserveSig] + int GetSimpleAudioVolume(ref Guid AudioSessionGuid, UInt32 StreamFlags, IntPtr /*ISimpleAudioVolume*/ SimpleAudioVolume); + [PreserveSig] + int GetSessionEnumerator(out IAudioSessionEnumerator SessionEnum); + [PreserveSig] + int RegisterSessionNotification( IntPtr IAudioSessionNotification ); + [PreserveSig] + int UnregisterSessionNotification( IntPtr IAudioSessionNotification ); + [PreserveSig] + int RegisterDuckNotification( string sessionID, IntPtr IAudioVolumeDuckNotification); + [PreserveSig] + int UnregisterDuckNotification(IntPtr IAudioVolumeDuckNotification); + }; +} diff --git a/AppleWirelessKeyboard/CoreAudioAPI/IMMDevice.cs b/AppleWirelessKeyboard/CoreAudioAPI/IMMDevice.cs new file mode 100644 index 0000000..c79ac4b --- /dev/null +++ b/AppleWirelessKeyboard/CoreAudioAPI/IMMDevice.cs @@ -0,0 +1,42 @@ +/* + LICENSE + ------- + Copyright (C) 2007-2010 Ray Molenkamp + + This source code is provided 'as-is', without any express or implied + warranty. In no event will the authors be held liable for any damages + arising from the use of this source code or the software it produces. + + Permission is granted to anyone to use this source code for any purpose, + including commercial applications, and to alter it and redistribute it + freely, subject to the following restrictions: + + 1. The origin of this source code must not be misrepresented; you must not + claim that you wrote the original source code. If you use this source code + in a product, an acknowledgment in the product documentation would be + appreciated but is not required. + 2. Altered source versions must be plainly marked as such, and must not be + misrepresented as being the original source code. + 3. This notice may not be removed or altered from any source distribution. +*/ +using System; +using System.Collections.Generic; +using System.Text; +using System.Runtime.InteropServices; + +namespace CoreAudioApi.Interfaces +{ + [Guid("D666063F-1587-4E43-81F1-B948E807363F"), + InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] + internal interface IMMDevice + { + [PreserveSig] + int Activate(ref Guid iid, CLSCTX dwClsCtx, IntPtr pActivationParams, [MarshalAs(UnmanagedType.IUnknown)] out object ppInterface); + [PreserveSig] + int OpenPropertyStore(EStgmAccess stgmAccess, out IPropertyStore propertyStore); + [PreserveSig] + int GetId([MarshalAs(UnmanagedType.LPWStr)] out string ppstrId); + [PreserveSig] + int GetState(out EDeviceState pdwState); + } +} diff --git a/AppleWirelessKeyboard/CoreAudioAPI/IMMDeviceCollection.cs b/AppleWirelessKeyboard/CoreAudioAPI/IMMDeviceCollection.cs new file mode 100644 index 0000000..eb0e58f --- /dev/null +++ b/AppleWirelessKeyboard/CoreAudioAPI/IMMDeviceCollection.cs @@ -0,0 +1,38 @@ +/* + LICENSE + ------- + Copyright (C) 2007-2010 Ray Molenkamp + + This source code is provided 'as-is', without any express or implied + warranty. In no event will the authors be held liable for any damages + arising from the use of this source code or the software it produces. + + Permission is granted to anyone to use this source code for any purpose, + including commercial applications, and to alter it and redistribute it + freely, subject to the following restrictions: + + 1. The origin of this source code must not be misrepresented; you must not + claim that you wrote the original source code. If you use this source code + in a product, an acknowledgment in the product documentation would be + appreciated but is not required. + 2. Altered source versions must be plainly marked as such, and must not be + misrepresented as being the original source code. + 3. This notice may not be removed or altered from any source distribution. +*/ +using System; +using System.Collections.Generic; +using System.Text; +using System.Runtime.InteropServices; + +namespace CoreAudioApi.Interfaces +{ + [Guid("0BD7A1BE-7A1A-44DB-8397-CC5392387B5E"), + InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] + internal interface IMMDeviceCollection + { + [PreserveSig] + int GetCount(out uint pcDevices); + [PreserveSig] + int Item(uint nDevice, out IMMDevice Device); + } +} diff --git a/AppleWirelessKeyboard/CoreAudioAPI/IMMDeviceEnumerator.cs b/AppleWirelessKeyboard/CoreAudioAPI/IMMDeviceEnumerator.cs new file mode 100644 index 0000000..68b1f8c --- /dev/null +++ b/AppleWirelessKeyboard/CoreAudioAPI/IMMDeviceEnumerator.cs @@ -0,0 +1,44 @@ +/* + LICENSE + ------- + Copyright (C) 2007-2010 Ray Molenkamp + + This source code is provided 'as-is', without any express or implied + warranty. In no event will the authors be held liable for any damages + arising from the use of this source code or the software it produces. + + Permission is granted to anyone to use this source code for any purpose, + including commercial applications, and to alter it and redistribute it + freely, subject to the following restrictions: + + 1. The origin of this source code must not be misrepresented; you must not + claim that you wrote the original source code. If you use this source code + in a product, an acknowledgment in the product documentation would be + appreciated but is not required. + 2. Altered source versions must be plainly marked as such, and must not be + misrepresented as being the original source code. + 3. This notice may not be removed or altered from any source distribution. +*/ +using System; +using System.Collections.Generic; +using System.Text; +using System.Runtime.InteropServices; + +namespace CoreAudioApi.Interfaces +{ + [Guid("A95664D2-9614-4F35-A746-DE8DB63617E6"), + InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] + internal interface IMMDeviceEnumerator + { + [PreserveSig] + int EnumAudioEndpoints(EDataFlow dataFlow, EDeviceState StateMask, out IMMDeviceCollection device); + [PreserveSig] + int GetDefaultAudioEndpoint(EDataFlow dataFlow, ERole role, out IMMDevice ppEndpoint); + [PreserveSig] + int GetDevice(string pwstrId, out IMMDevice ppDevice); + [PreserveSig] + int RegisterEndpointNotificationCallback(IntPtr pClient); + [PreserveSig] + int UnregisterEndpointNotificationCallback(IntPtr pClient); + } +} diff --git a/AppleWirelessKeyboard/CoreAudioAPI/IMMEndpoint.cs b/AppleWirelessKeyboard/CoreAudioAPI/IMMEndpoint.cs new file mode 100644 index 0000000..ccc5de4 --- /dev/null +++ b/AppleWirelessKeyboard/CoreAudioAPI/IMMEndpoint.cs @@ -0,0 +1,36 @@ +/* + LICENSE + ------- + Copyright (C) 2007-2010 Ray Molenkamp + + This source code is provided 'as-is', without any express or implied + warranty. In no event will the authors be held liable for any damages + arising from the use of this source code or the software it produces. + + Permission is granted to anyone to use this source code for any purpose, + including commercial applications, and to alter it and redistribute it + freely, subject to the following restrictions: + + 1. The origin of this source code must not be misrepresented; you must not + claim that you wrote the original source code. If you use this source code + in a product, an acknowledgment in the product documentation would be + appreciated but is not required. + 2. Altered source versions must be plainly marked as such, and must not be + misrepresented as being the original source code. + 3. This notice may not be removed or altered from any source distribution. +*/ +using System; +using System.Collections.Generic; +using System.Text; +using System.Runtime.InteropServices; + +namespace CoreAudioApi.Interfaces +{ + [Guid("1BE09788-6894-4089-8586-9A2A6C265AC5"), + InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] + internal interface IMMEndpoint + { + [PreserveSig] + int GetDataFlow(out EDataFlow pDataFlow); + }; +} diff --git a/AppleWirelessKeyboard/CoreAudioAPI/IPropertyStore.cs b/AppleWirelessKeyboard/CoreAudioAPI/IPropertyStore.cs new file mode 100644 index 0000000..70b22c8 --- /dev/null +++ b/AppleWirelessKeyboard/CoreAudioAPI/IPropertyStore.cs @@ -0,0 +1,44 @@ +/* + LICENSE + ------- + Copyright (C) 2007-2010 Ray Molenkamp + + This source code is provided 'as-is', without any express or implied + warranty. In no event will the authors be held liable for any damages + arising from the use of this source code or the software it produces. + + Permission is granted to anyone to use this source code for any purpose, + including commercial applications, and to alter it and redistribute it + freely, subject to the following restrictions: + + 1. The origin of this source code must not be misrepresented; you must not + claim that you wrote the original source code. If you use this source code + in a product, an acknowledgment in the product documentation would be + appreciated but is not required. + 2. Altered source versions must be plainly marked as such, and must not be + misrepresented as being the original source code. + 3. This notice may not be removed or altered from any source distribution. +*/ +using System; +using System.Collections.Generic; +using System.Text; +using System.Runtime.InteropServices; + +namespace CoreAudioApi.Interfaces +{ + [Guid("886d8eeb-8cf2-4446-8d02-cdba1dbdcf99"), + InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] + internal interface IPropertyStore + { + [PreserveSig] + int GetCount( out Int32 count); + [PreserveSig] + int GetAt( int iProp, out PropertyKey pkey); + [PreserveSig] + int GetValue(ref PropertyKey key, out PropVariant pv); + [PreserveSig] + int SetValue(ref PropertyKey key, ref PropVariant propvar); + [PreserveSig] + int Commit( ); + }; +} diff --git a/AppleWirelessKeyboard/CoreAudioAPI/ISimpleAudioVolume.cs b/AppleWirelessKeyboard/CoreAudioAPI/ISimpleAudioVolume.cs new file mode 100644 index 0000000..8d47d86 --- /dev/null +++ b/AppleWirelessKeyboard/CoreAudioAPI/ISimpleAudioVolume.cs @@ -0,0 +1,43 @@ +/* + LICENSE + ------- + Copyright (C) 2007-2010 Ray Molenkamp + + This source code is provided 'as-is', without any express or implied + warranty. In no event will the authors be held liable for any damages + arising from the use of this source code or the software it produces. + + Permission is granted to anyone to use this source code for any purpose, + including commercial applications, and to alter it and redistribute it + freely, subject to the following restrictions: + + 1. The origin of this source code must not be misrepresented; you must not + claim that you wrote the original source code. If you use this source code + in a product, an acknowledgment in the product documentation would be + appreciated but is not required. + 2. Altered source versions must be plainly marked as such, and must not be + misrepresented as being the original source code. + 3. This notice may not be removed or altered from any source distribution. +*/ +using System; +using System.Collections.Generic; +using System.Text; +using System.Runtime.InteropServices; + + +namespace CoreAudioApi.Interfaces +{ + [Guid("87CE5498-68D6-44E5-9215-6DA47EF883D8"), + InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] + internal interface ISimpleAudioVolume + { + [PreserveSig] + int SetMasterVolume( float fLevel,ref Guid EventContext); + [PreserveSig] + int GetMasterVolume( out float pfLevel); + [PreserveSig] + int SetMute( bool bMute, ref Guid EventContext) ; + [PreserveSig] + int GetMute( out bool bMute); + } +} diff --git a/AppleWirelessKeyboard/CoreAudioAPI/MMDevice.cs b/AppleWirelessKeyboard/CoreAudioAPI/MMDevice.cs new file mode 100644 index 0000000..7563750 --- /dev/null +++ b/AppleWirelessKeyboard/CoreAudioAPI/MMDevice.cs @@ -0,0 +1,180 @@ +/* + LICENSE + ------- + Copyright (C) 2007-2010 Ray Molenkamp + + This source code is provided 'as-is', without any express or implied + warranty. In no event will the authors be held liable for any damages + arising from the use of this source code or the software it produces. + + Permission is granted to anyone to use this source code for any purpose, + including commercial applications, and to alter it and redistribute it + freely, subject to the following restrictions: + + 1. The origin of this source code must not be misrepresented; you must not + claim that you wrote the original source code. If you use this source code + in a product, an acknowledgment in the product documentation would be + appreciated but is not required. + 2. Altered source versions must be plainly marked as such, and must not be + misrepresented as being the original source code. + 3. This notice may not be removed or altered from any source distribution. +*/ +using System; +using System.Collections.Generic; +using System.Text; +using CoreAudioApi.Interfaces; +using System.Runtime.InteropServices; + +namespace CoreAudioApi +{ + public class MMDevice + { + #region Variables + private IMMDevice _RealDevice; + private PropertyStore _PropertyStore; + private AudioMeterInformation _AudioMeterInformation; + private AudioEndpointVolume _AudioEndpointVolume; + private AudioSessionManager _AudioSessionManager; + + #endregion + + #region Guids + private static Guid IID_IAudioMeterInformation = typeof(IAudioMeterInformation).GUID; + private static Guid IID_IAudioEndpointVolume = typeof(IAudioEndpointVolume).GUID; + private static Guid IID_IAudioSessionManager = typeof(IAudioSessionManager2).GUID; + #endregion + + #region Init + private void GetPropertyInformation() + { + IPropertyStore propstore; + Marshal.ThrowExceptionForHR(_RealDevice.OpenPropertyStore(EStgmAccess.STGM_READ, out propstore)); + _PropertyStore = new PropertyStore(propstore); + } + + private void GetAudioSessionManager() + { + object result; + Marshal.ThrowExceptionForHR(_RealDevice.Activate(ref IID_IAudioSessionManager, CLSCTX.ALL, IntPtr.Zero, out result)); + _AudioSessionManager = new AudioSessionManager(result as IAudioSessionManager2); + } + + private void GetAudioMeterInformation() + { + object result; + Marshal.ThrowExceptionForHR( _RealDevice.Activate(ref IID_IAudioMeterInformation, CLSCTX.ALL, IntPtr.Zero, out result)); + _AudioMeterInformation = new AudioMeterInformation( result as IAudioMeterInformation); + } + + private void GetAudioEndpointVolume() + { + object result; + Marshal.ThrowExceptionForHR(_RealDevice.Activate(ref IID_IAudioEndpointVolume, CLSCTX.ALL, IntPtr.Zero, out result)); + _AudioEndpointVolume = new AudioEndpointVolume(result as IAudioEndpointVolume); + } + + #endregion + + #region Properties + + public AudioSessionManager AudioSessionManager + { + get + { + if (_AudioSessionManager == null) + GetAudioSessionManager(); + + return _AudioSessionManager; + } + } + + public AudioMeterInformation AudioMeterInformation + { + get + { + if (_AudioMeterInformation == null) + GetAudioMeterInformation(); + + return _AudioMeterInformation; + } + } + + public AudioEndpointVolume AudioEndpointVolume + { + get + { + if (_AudioEndpointVolume == null) + GetAudioEndpointVolume(); + + return _AudioEndpointVolume; + } + } + + public PropertyStore Properties + { + get + { + if (_PropertyStore == null) + GetPropertyInformation(); + return _PropertyStore; + } + } + + public string FriendlyName + { + get + { + if (_PropertyStore == null) + GetPropertyInformation(); + if (_PropertyStore.Contains(PKEY.PKEY_DeviceInterface_FriendlyName)) + { + return (string)_PropertyStore[PKEY.PKEY_DeviceInterface_FriendlyName].Value; + } + else + return "Unknown"; + } + } + + + public string ID + { + get + { + string Result; + Marshal.ThrowExceptionForHR(_RealDevice.GetId(out Result)); + return Result; + } + } + + public EDataFlow DataFlow + { + get + { + EDataFlow Result; + IMMEndpoint ep = _RealDevice as IMMEndpoint ; + ep.GetDataFlow(out Result); + return Result; + } + } + + public EDeviceState State + { + get + { + EDeviceState Result; + Marshal.ThrowExceptionForHR(_RealDevice.GetState(out Result)); + return Result; + + } + } + #endregion + + #region Constructor + internal MMDevice(IMMDevice realDevice) + { + _RealDevice = realDevice; + } + #endregion + + } +} diff --git a/AppleWirelessKeyboard/CoreAudioAPI/MMDeviceCollection.cs b/AppleWirelessKeyboard/CoreAudioAPI/MMDeviceCollection.cs new file mode 100644 index 0000000..a2b96d2 --- /dev/null +++ b/AppleWirelessKeyboard/CoreAudioAPI/MMDeviceCollection.cs @@ -0,0 +1,59 @@ +/* + LICENSE + ------- + Copyright (C) 2007-2010 Ray Molenkamp + + This source code is provided 'as-is', without any express or implied + warranty. In no event will the authors be held liable for any damages + arising from the use of this source code or the software it produces. + + Permission is granted to anyone to use this source code for any purpose, + including commercial applications, and to alter it and redistribute it + freely, subject to the following restrictions: + + 1. The origin of this source code must not be misrepresented; you must not + claim that you wrote the original source code. If you use this source code + in a product, an acknowledgment in the product documentation would be + appreciated but is not required. + 2. Altered source versions must be plainly marked as such, and must not be + misrepresented as being the original source code. + 3. This notice may not be removed or altered from any source distribution. +*/ +using System; +using System.Collections.Generic; +using System.Text; +using System.Runtime.InteropServices; +using CoreAudioApi.Interfaces; + +namespace CoreAudioApi +{ + public class MMDeviceCollection + { + private IMMDeviceCollection _MMDeviceCollection; + + public int Count + { + get + { + uint result; + Marshal.ThrowExceptionForHR(_MMDeviceCollection.GetCount(out result)); + return (int)result; + } + } + + public MMDevice this[int index] + { + get + { + IMMDevice result; + _MMDeviceCollection.Item((uint)index, out result); + return new MMDevice(result); + } + } + + internal MMDeviceCollection(IMMDeviceCollection parent) + { + _MMDeviceCollection = parent; + } + } +} diff --git a/AppleWirelessKeyboard/CoreAudioAPI/MMDeviceEnumerator.cs b/AppleWirelessKeyboard/CoreAudioAPI/MMDeviceEnumerator.cs new file mode 100644 index 0000000..91ba5d6 --- /dev/null +++ b/AppleWirelessKeyboard/CoreAudioAPI/MMDeviceEnumerator.cs @@ -0,0 +1,70 @@ +/* + LICENSE + ------- + Copyright (C) 2007-2010 Ray Molenkamp + + This source code is provided 'as-is', without any express or implied + warranty. In no event will the authors be held liable for any damages + arising from the use of this source code or the software it produces. + + Permission is granted to anyone to use this source code for any purpose, + including commercial applications, and to alter it and redistribute it + freely, subject to the following restrictions: + + 1. The origin of this source code must not be misrepresented; you must not + claim that you wrote the original source code. If you use this source code + in a product, an acknowledgment in the product documentation would be + appreciated but is not required. + 2. Altered source versions must be plainly marked as such, and must not be + misrepresented as being the original source code. + 3. This notice may not be removed or altered from any source distribution. +*/ +using System; +using System.Collections.Generic; +using System.Text; +using System.Runtime.InteropServices; +using CoreAudioApi.Interfaces; + +namespace CoreAudioApi +{ + //Marked as internal, since on its own its no good + [ComImport, Guid("BCDE0395-E52F-467C-8E3D-C4579291692E")] + internal class _MMDeviceEnumerator + { + } + + //Small wrapper class + public class MMDeviceEnumerator + { + private IMMDeviceEnumerator _realEnumerator = new _MMDeviceEnumerator() as IMMDeviceEnumerator; + + public MMDeviceCollection EnumerateAudioEndPoints(EDataFlow dataFlow, EDeviceState dwStateMask) + { + IMMDeviceCollection result; + Marshal.ThrowExceptionForHR(_realEnumerator.EnumAudioEndpoints(dataFlow,dwStateMask,out result)); + return new MMDeviceCollection(result); + } + + public MMDevice GetDefaultAudioEndpoint(EDataFlow dataFlow, ERole role) + { + IMMDevice _Device = null; + Marshal.ThrowExceptionForHR(((IMMDeviceEnumerator)_realEnumerator).GetDefaultAudioEndpoint(dataFlow, role, out _Device)); + return new MMDevice(_Device); + } + + public MMDevice GetDevice(string ID) + { + IMMDevice _Device = null; + Marshal.ThrowExceptionForHR(((IMMDeviceEnumerator)_realEnumerator).GetDevice(ID, out _Device)); + return new MMDevice(_Device); + } + + public MMDeviceEnumerator() + { + if (System.Environment.OSVersion.Version.Major < 6) + { + throw new NotSupportedException("This functionality is only supported on Windows Vista or newer."); + } + } + } +} diff --git a/AppleWirelessKeyboard/CoreAudioAPI/PKEY.cs b/AppleWirelessKeyboard/CoreAudioAPI/PKEY.cs new file mode 100644 index 0000000..fda79b5 --- /dev/null +++ b/AppleWirelessKeyboard/CoreAudioAPI/PKEY.cs @@ -0,0 +1,41 @@ +/* + LICENSE + ------- + Copyright (C) 2007-2010 Ray Molenkamp + + This source code is provided 'as-is', without any express or implied + warranty. In no event will the authors be held liable for any damages + arising from the use of this source code or the software it produces. + + Permission is granted to anyone to use this source code for any purpose, + including commercial applications, and to alter it and redistribute it + freely, subject to the following restrictions: + + 1. The origin of this source code must not be misrepresented; you must not + claim that you wrote the original source code. If you use this source code + in a product, an acknowledgment in the product documentation would be + appreciated but is not required. + 2. Altered source versions must be plainly marked as such, and must not be + misrepresented as being the original source code. + 3. This notice may not be removed or altered from any source distribution. +*/ +using System; +using System.Collections.Generic; +using System.Text; + +namespace CoreAudioApi +{ + public static class PKEY + { + public static readonly Guid PKEY_DeviceInterface_FriendlyName = new Guid( 0xa45c254e, 0xdf1c, 0x4efd, 0x80, 0x20, 0x67, 0xd1, 0x46, 0xa8, 0x50, 0xe0); + public static readonly Guid PKEY_AudioEndpoint_FormFactor = new Guid( 0x1da5d803, 0xd492, 0x4edd, 0x8c, 0x23, 0xe0, 0xc0, 0xff, 0xee, 0x7f, 0x0e); + public static readonly Guid PKEY_AudioEndpoint_ControlPanelPageProvider = new Guid( 0x1da5d803, 0xd492, 0x4edd, 0x8c, 0x23, 0xe0, 0xc0, 0xff, 0xee, 0x7f, 0x0e); + public static readonly Guid PKEY_AudioEndpoint_Association = new Guid( 0x1da5d803, 0xd492, 0x4edd, 0x8c, 0x23, 0xe0, 0xc0, 0xff, 0xee, 0x7f, 0x0e); + public static readonly Guid PKEY_AudioEndpoint_PhysicalSpeakers = new Guid( 0x1da5d803, 0xd492, 0x4edd, 0x8c, 0x23, 0xe0, 0xc0, 0xff, 0xee, 0x7f, 0x0e); + public static readonly Guid PKEY_AudioEndpoint_GUID = new Guid( 0x1da5d803, 0xd492, 0x4edd, 0x8c, 0x23, 0xe0, 0xc0, 0xff, 0xee, 0x7f, 0x0e); + public static readonly Guid PKEY_AudioEndpoint_Disable_SysFx = new Guid( 0x1da5d803, 0xd492, 0x4edd, 0x8c, 0x23, 0xe0, 0xc0, 0xff, 0xee, 0x7f, 0x0e); + public static readonly Guid PKEY_AudioEndpoint_FullRangeSpeakers = new Guid( 0x1da5d803, 0xd492, 0x4edd, 0x8c, 0x23, 0xe0, 0xc0, 0xff, 0xee, 0x7f, 0x0e); + public static readonly Guid PKEY_AudioEngine_DeviceFormat = new Guid(0xf19f064d, 0x82c, 0x4e27, 0xbc, 0x73, 0x68, 0x82, 0xa1, 0xbb, 0x8e, 0x4c); + + } +} diff --git a/AppleWirelessKeyboard/CoreAudioAPI/PropVariant.cs b/AppleWirelessKeyboard/CoreAudioAPI/PropVariant.cs new file mode 100644 index 0000000..92e5367 --- /dev/null +++ b/AppleWirelessKeyboard/CoreAudioAPI/PropVariant.cs @@ -0,0 +1,96 @@ +/* + LICENSE + ------- + Copyright (C) 2007-2010 Ray Molenkamp + + This source code is provided 'as-is', without any express or implied + warranty. In no event will the authors be held liable for any damages + arising from the use of this source code or the software it produces. + + Permission is granted to anyone to use this source code for any purpose, + including commercial applications, and to alter it and redistribute it + freely, subject to the following restrictions: + + 1. The origin of this source code must not be misrepresented; you must not + claim that you wrote the original source code. If you use this source code + in a product, an acknowledgment in the product documentation would be + appreciated but is not required. + 2. Altered source versions must be plainly marked as such, and must not be + misrepresented as being the original source code. + 3. This notice may not be removed or altered from any source distribution. +*/ + +using System; +using System.Collections.Generic; +using System.Text; +using System.Runtime.InteropServices.ComTypes; +using System.Runtime.InteropServices; +using CoreAudioApi.Interfaces; + +namespace CoreAudioApi +{ + [StructLayout(LayoutKind.Explicit)] + public struct PropVariant + { + [FieldOffset(0)] short vt; + [FieldOffset(2)] short wReserved1; + [FieldOffset(4)] short wReserved2; + [FieldOffset(6)] short wReserved3; + [FieldOffset(8)] sbyte cVal; + [FieldOffset(8)] byte bVal; + [FieldOffset(8)] short iVal; + [FieldOffset(8)] ushort uiVal; + [FieldOffset(8)] int lVal; + [FieldOffset(8)] uint ulVal; + [FieldOffset(8)] long hVal; + [FieldOffset(8)] ulong uhVal; + [FieldOffset(8)] float fltVal; + [FieldOffset(8)] double dblVal; + [FieldOffset(8)] Blob blobVal; + [FieldOffset(8)] DateTime date; + [FieldOffset(8)] bool boolVal; + [FieldOffset(8)] int scode; + [FieldOffset(8)] System.Runtime.InteropServices.ComTypes.FILETIME filetime; + [FieldOffset(8)] IntPtr everything_else; + + //I'm sure there is a more efficient way to do this but this works ..for now.. + internal byte[] GetBlob() + { + byte[] Result = new byte[blobVal.Length]; + for (int i = 0; i < blobVal.Length; i++) + { + Result[i] = Marshal.ReadByte((IntPtr) ((long)(blobVal.Data) + i)); + } + return Result; + } + + public object Value + { + get + { + VarEnum ve = (VarEnum)vt; + switch (ve) + { + case VarEnum.VT_I1: + return bVal; + case VarEnum.VT_I2: + return iVal; + case VarEnum.VT_I4: + return lVal; + case VarEnum.VT_I8: + return hVal; + case VarEnum.VT_INT: + return iVal; + case VarEnum.VT_UI4: + return ulVal; + case VarEnum.VT_LPWSTR: + return Marshal.PtrToStringUni(everything_else); + case VarEnum.VT_BLOB: + return GetBlob(); + } + return "FIXME Type = " + ve.ToString(); + } + } + + } +} diff --git a/AppleWirelessKeyboard/CoreAudioAPI/PropertyKey.cs b/AppleWirelessKeyboard/CoreAudioAPI/PropertyKey.cs new file mode 100644 index 0000000..14dadc3 --- /dev/null +++ b/AppleWirelessKeyboard/CoreAudioAPI/PropertyKey.cs @@ -0,0 +1,34 @@ +/* + LICENSE + ------- + Copyright (C) 2007-2010 Ray Molenkamp + + This source code is provided 'as-is', without any express or implied + warranty. In no event will the authors be held liable for any damages + arising from the use of this source code or the software it produces. + + Permission is granted to anyone to use this source code for any purpose, + including commercial applications, and to alter it and redistribute it + freely, subject to the following restrictions: + + 1. The origin of this source code must not be misrepresented; you must not + claim that you wrote the original source code. If you use this source code + in a product, an acknowledgment in the product documentation would be + appreciated but is not required. + 2. Altered source versions must be plainly marked as such, and must not be + misrepresented as being the original source code. + 3. This notice may not be removed or altered from any source distribution. +*/ +using System; +using System.Collections.Generic; +using System.Text; + +namespace CoreAudioApi +{ + public struct PropertyKey + { + public Guid fmtid; + public int pid; + }; + +} diff --git a/AppleWirelessKeyboard/CoreAudioAPI/PropertyStore.cs b/AppleWirelessKeyboard/CoreAudioAPI/PropertyStore.cs new file mode 100644 index 0000000..3651e39 --- /dev/null +++ b/AppleWirelessKeyboard/CoreAudioAPI/PropertyStore.cs @@ -0,0 +1,107 @@ +/* + LICENSE + ------- + Copyright (C) 2007-2010 Ray Molenkamp + + This source code is provided 'as-is', without any express or implied + warranty. In no event will the authors be held liable for any damages + arising from the use of this source code or the software it produces. + + Permission is granted to anyone to use this source code for any purpose, + including commercial applications, and to alter it and redistribute it + freely, subject to the following restrictions: + + 1. The origin of this source code must not be misrepresented; you must not + claim that you wrote the original source code. If you use this source code + in a product, an acknowledgment in the product documentation would be + appreciated but is not required. + 2. Altered source versions must be plainly marked as such, and must not be + misrepresented as being the original source code. + 3. This notice may not be removed or altered from any source distribution. +*/ +using System; +using System.Collections.Generic; +using System.Text; +using CoreAudioApi.Interfaces; +using System.Runtime.InteropServices; + +namespace CoreAudioApi +{ + /// + /// Property Store class, only supports reading properties at the moment. + /// + public class PropertyStore + { + private IPropertyStore _Store; + + public int Count + { + get + { + int Result; + Marshal.ThrowExceptionForHR(_Store.GetCount(out Result)); + return Result; + } + } + + public PropertyStoreProperty this[int index] + { + get + { + PropVariant result; + PropertyKey key = Get(index); + Marshal.ThrowExceptionForHR(_Store.GetValue(ref key, out result)); + return new PropertyStoreProperty(key, result); + } + } + + public bool Contains(Guid guid) + { + for (int i = 0; i < Count; i++) + { + PropertyKey key = Get(i); + if (key.fmtid == guid) + return true; + } + return false; + } + + public PropertyStoreProperty this[Guid guid] + { + get + { + PropVariant result; + for (int i = 0; i < Count; i++) + { + PropertyKey key = Get(i); + if (key.fmtid == guid) + { + Marshal.ThrowExceptionForHR(_Store.GetValue(ref key, out result)); + return new PropertyStoreProperty(key, result); + } + } + return null; + } + } + + public PropertyKey Get(int index) + { + PropertyKey key; + Marshal.ThrowExceptionForHR( _Store.GetAt(index, out key)); + return key; + } + + public PropVariant GetValue(int index) + { + PropVariant result; + PropertyKey key = Get(index); + Marshal.ThrowExceptionForHR(_Store.GetValue(ref key, out result)); + return result; + } + + internal PropertyStore(IPropertyStore store) + { + _Store = store; + } + } +} diff --git a/AppleWirelessKeyboard/CoreAudioAPI/PropertyStoreProperty.cs b/AppleWirelessKeyboard/CoreAudioAPI/PropertyStoreProperty.cs new file mode 100644 index 0000000..2090f0a --- /dev/null +++ b/AppleWirelessKeyboard/CoreAudioAPI/PropertyStoreProperty.cs @@ -0,0 +1,57 @@ +/* + LICENSE + ------- + Copyright (C) 2007-2010 Ray Molenkamp + + This source code is provided 'as-is', without any express or implied + warranty. In no event will the authors be held liable for any damages + arising from the use of this source code or the software it produces. + + Permission is granted to anyone to use this source code for any purpose, + including commercial applications, and to alter it and redistribute it + freely, subject to the following restrictions: + + 1. The origin of this source code must not be misrepresented; you must not + claim that you wrote the original source code. If you use this source code + in a product, an acknowledgment in the product documentation would be + appreciated but is not required. + 2. Altered source versions must be plainly marked as such, and must not be + misrepresented as being the original source code. + 3. This notice may not be removed or altered from any source distribution. +*/ + +using System; +using System.Collections.Generic; +using System.Text; +using CoreAudioApi.Interfaces; + +namespace CoreAudioApi +{ + public class PropertyStoreProperty + { + private PropertyKey _PropertyKey; + private PropVariant _PropValue; + + internal PropertyStoreProperty(PropertyKey key, PropVariant value) + { + _PropertyKey = key; + _PropValue = value; + } + + public PropertyKey Key + { + get + { + return _PropertyKey; + } + } + + public object Value + { + get + { + return _PropValue.Value; + } + } + } +} diff --git a/AppleWirelessKeyboard/CoreAudioAPI/SessionCollection.cs b/AppleWirelessKeyboard/CoreAudioAPI/SessionCollection.cs new file mode 100644 index 0000000..1260e5e --- /dev/null +++ b/AppleWirelessKeyboard/CoreAudioAPI/SessionCollection.cs @@ -0,0 +1,60 @@ +/* + LICENSE + ------- + Copyright (C) 2007-2010 Ray Molenkamp + + This source code is provided 'as-is', without any express or implied + warranty. In no event will the authors be held liable for any damages + arising from the use of this source code or the software it produces. + + Permission is granted to anyone to use this source code for any purpose, + including commercial applications, and to alter it and redistribute it + freely, subject to the following restrictions: + + 1. The origin of this source code must not be misrepresented; you must not + claim that you wrote the original source code. If you use this source code + in a product, an acknowledgment in the product documentation would be + appreciated but is not required. + 2. Altered source versions must be plainly marked as such, and must not be + misrepresented as being the original source code. + 3. This notice may not be removed or altered from any source distribution. +*/ + +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using CoreAudioApi.Interfaces; +using System.Runtime.InteropServices; + +namespace CoreAudioApi +{ + public class SessionCollection + { + IAudioSessionEnumerator _AudioSessionEnumerator; + internal SessionCollection(IAudioSessionEnumerator realEnumerator) + { + _AudioSessionEnumerator = realEnumerator; + } + + public AudioSessionControl this[int index] + { + get + { + IAudioSessionControl2 _Result; + Marshal.ThrowExceptionForHR(_AudioSessionEnumerator.GetSession(index, out _Result)); + return new AudioSessionControl(_Result); + } + } + + public int Count + { + get + { + int result; + Marshal.ThrowExceptionForHR(_AudioSessionEnumerator.GetCount(out result)); + return (int)result; + } + } + } +} diff --git a/AppleWirelessKeyboard/CoreAudioAPI/SimpleAudioVolume.cs b/AppleWirelessKeyboard/CoreAudioAPI/SimpleAudioVolume.cs new file mode 100644 index 0000000..c46bacd --- /dev/null +++ b/AppleWirelessKeyboard/CoreAudioAPI/SimpleAudioVolume.cs @@ -0,0 +1,70 @@ +/* + LICENSE + ------- + Copyright (C) 2007-2010 Ray Molenkamp + + This source code is provided 'as-is', without any express or implied + warranty. In no event will the authors be held liable for any damages + arising from the use of this source code or the software it produces. + + Permission is granted to anyone to use this source code for any purpose, + including commercial applications, and to alter it and redistribute it + freely, subject to the following restrictions: + + 1. The origin of this source code must not be misrepresented; you must not + claim that you wrote the original source code. If you use this source code + in a product, an acknowledgment in the product documentation would be + appreciated but is not required. + 2. Altered source versions must be plainly marked as such, and must not be + misrepresented as being the original source code. + 3. This notice may not be removed or altered from any source distribution. +*/ + +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using CoreAudioApi.Interfaces; +using System.Runtime.InteropServices; + +namespace CoreAudioApi +{ + public class SimpleAudioVolume + { + ISimpleAudioVolume _SimpleAudioVolume; + internal SimpleAudioVolume(ISimpleAudioVolume realSimpleVolume) + { + _SimpleAudioVolume = realSimpleVolume; + } + + public float MasterVolume + { + get + { + float ret; + Marshal.ThrowExceptionForHR(_SimpleAudioVolume.GetMasterVolume(out ret)); + return ret; + } + set + { + Guid Empty = Guid.Empty; + Marshal.ThrowExceptionForHR(_SimpleAudioVolume.SetMasterVolume(value, ref Empty)); + } + } + + public bool Mute + { + get + { + bool ret; + Marshal.ThrowExceptionForHR(_SimpleAudioVolume.GetMute(out ret)); + return ret; + } + set + { + Guid Empty = Guid.Empty; + Marshal.ThrowExceptionForHR(_SimpleAudioVolume.SetMute(value, ref Empty)); + } + } + } +} diff --git a/AppleWirelessKeyboard/CoreAudioAPI/eStgmAccess.cs b/AppleWirelessKeyboard/CoreAudioAPI/eStgmAccess.cs new file mode 100644 index 0000000..17dbb8b --- /dev/null +++ b/AppleWirelessKeyboard/CoreAudioAPI/eStgmAccess.cs @@ -0,0 +1,34 @@ +/* + LICENSE + ------- + Copyright (C) 2007-2010 Ray Molenkamp + + This source code is provided 'as-is', without any express or implied + warranty. In no event will the authors be held liable for any damages + arising from the use of this source code or the software it produces. + + Permission is granted to anyone to use this source code for any purpose, + including commercial applications, and to alter it and redistribute it + freely, subject to the following restrictions: + + 1. The origin of this source code must not be misrepresented; you must not + claim that you wrote the original source code. If you use this source code + in a product, an acknowledgment in the product documentation would be + appreciated but is not required. + 2. Altered source versions must be plainly marked as such, and must not be + misrepresented as being the original source code. + 3. This notice may not be removed or altered from any source distribution. +*/ +using System; +using System.Collections.Generic; +using System.Text; + +namespace CoreAudioApi.Interfaces +{ + internal enum EStgmAccess + { + STGM_READ = 0x00000000, + STGM_WRITE = 0x00000001, + STGM_READWRITE = 0x00000002 + } +} diff --git a/AppleWirelessKeyboard/Glyphs/Eject.xaml b/AppleWirelessKeyboard/Glyphs/Eject.xaml new file mode 100644 index 0000000..97f87c2 --- /dev/null +++ b/AppleWirelessKeyboard/Glyphs/Eject.xaml @@ -0,0 +1,9 @@ + + + + + + + diff --git a/AppleWirelessKeyboard/Glyphs/Eject.xaml.cs b/AppleWirelessKeyboard/Glyphs/Eject.xaml.cs new file mode 100644 index 0000000..25c3ce8 --- /dev/null +++ b/AppleWirelessKeyboard/Glyphs/Eject.xaml.cs @@ -0,0 +1,27 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Data; +using System.Windows.Documents; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Imaging; +using System.Windows.Navigation; +using System.Windows.Shapes; + +namespace AppleWirelessKeyboard.Glyphs +{ + /// + /// Interaction logic for Eject.xaml + /// + public partial class Eject : UserControl + { + public Eject() + { + InitializeComponent(); + } + } +} diff --git a/AppleWirelessKeyboard/Glyphs/MuteOff.xaml b/AppleWirelessKeyboard/Glyphs/MuteOff.xaml new file mode 100644 index 0000000..4a036fb --- /dev/null +++ b/AppleWirelessKeyboard/Glyphs/MuteOff.xaml @@ -0,0 +1,13 @@ + + + + + + + + + + + diff --git a/AppleWirelessKeyboard/Glyphs/MuteOff.xaml.cs b/AppleWirelessKeyboard/Glyphs/MuteOff.xaml.cs new file mode 100644 index 0000000..18fb478 --- /dev/null +++ b/AppleWirelessKeyboard/Glyphs/MuteOff.xaml.cs @@ -0,0 +1,27 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Data; +using System.Windows.Documents; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Imaging; +using System.Windows.Navigation; +using System.Windows.Shapes; + +namespace AppleWirelessKeyboard.Glyphs +{ + /// + /// Interaction logic for MuteOff.xaml + /// + public partial class MuteOff : UserControl + { + public MuteOff() + { + InitializeComponent(); + } + } +} diff --git a/AppleWirelessKeyboard/Glyphs/MuteOn.xaml b/AppleWirelessKeyboard/Glyphs/MuteOn.xaml new file mode 100644 index 0000000..58feb64 --- /dev/null +++ b/AppleWirelessKeyboard/Glyphs/MuteOn.xaml @@ -0,0 +1,11 @@ + + + + + + + + + diff --git a/AppleWirelessKeyboard/Glyphs/MuteOn.xaml.cs b/AppleWirelessKeyboard/Glyphs/MuteOn.xaml.cs new file mode 100644 index 0000000..8f7b28a --- /dev/null +++ b/AppleWirelessKeyboard/Glyphs/MuteOn.xaml.cs @@ -0,0 +1,27 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Data; +using System.Windows.Documents; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Imaging; +using System.Windows.Navigation; +using System.Windows.Shapes; + +namespace AppleWirelessKeyboard.Glyphs +{ + /// + /// Interaction logic for MuteOn.xaml + /// + public partial class MuteOn : UserControl + { + public MuteOn() + { + InitializeComponent(); + } + } +} diff --git a/AppleWirelessKeyboard/Glyphs/Next.xaml b/AppleWirelessKeyboard/Glyphs/Next.xaml new file mode 100644 index 0000000..9e12423 --- /dev/null +++ b/AppleWirelessKeyboard/Glyphs/Next.xaml @@ -0,0 +1,8 @@ + + + + + + diff --git a/AppleWirelessKeyboard/Glyphs/Next.xaml.cs b/AppleWirelessKeyboard/Glyphs/Next.xaml.cs new file mode 100644 index 0000000..0e65c68 --- /dev/null +++ b/AppleWirelessKeyboard/Glyphs/Next.xaml.cs @@ -0,0 +1,27 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Data; +using System.Windows.Documents; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Imaging; +using System.Windows.Navigation; +using System.Windows.Shapes; + +namespace AppleWirelessKeyboard.Glyphs +{ + /// + /// Interaction logic for Next.xaml + /// + public partial class Next : UserControl + { + public Next() + { + InitializeComponent(); + } + } +} diff --git a/AppleWirelessKeyboard/Glyphs/Off.xaml b/AppleWirelessKeyboard/Glyphs/Off.xaml new file mode 100644 index 0000000..72df273 --- /dev/null +++ b/AppleWirelessKeyboard/Glyphs/Off.xaml @@ -0,0 +1,7 @@ + + + + + diff --git a/AppleWirelessKeyboard/Glyphs/Off.xaml.cs b/AppleWirelessKeyboard/Glyphs/Off.xaml.cs new file mode 100644 index 0000000..b3ca1a3 --- /dev/null +++ b/AppleWirelessKeyboard/Glyphs/Off.xaml.cs @@ -0,0 +1,27 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Data; +using System.Windows.Documents; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Imaging; +using System.Windows.Navigation; +using System.Windows.Shapes; + +namespace AppleWirelessKeyboard.Glyphs +{ + /// + /// Interaction logic for Off.xaml + /// + public partial class Off : UserControl + { + public Off() + { + InitializeComponent(); + } + } +} diff --git a/AppleWirelessKeyboard/Glyphs/On.xaml b/AppleWirelessKeyboard/Glyphs/On.xaml new file mode 100644 index 0000000..67c41ee --- /dev/null +++ b/AppleWirelessKeyboard/Glyphs/On.xaml @@ -0,0 +1,7 @@ + + + + + diff --git a/AppleWirelessKeyboard/Glyphs/On.xaml.cs b/AppleWirelessKeyboard/Glyphs/On.xaml.cs new file mode 100644 index 0000000..cdca88d --- /dev/null +++ b/AppleWirelessKeyboard/Glyphs/On.xaml.cs @@ -0,0 +1,27 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Data; +using System.Windows.Documents; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Imaging; +using System.Windows.Navigation; +using System.Windows.Shapes; + +namespace AppleWirelessKeyboard.Glyphs +{ + /// + /// Interaction logic for On.xaml + /// + public partial class On : UserControl + { + public On() + { + InitializeComponent(); + } + } +} diff --git a/AppleWirelessKeyboard/Glyphs/PlayPause.xaml b/AppleWirelessKeyboard/Glyphs/PlayPause.xaml new file mode 100644 index 0000000..10fbe12 --- /dev/null +++ b/AppleWirelessKeyboard/Glyphs/PlayPause.xaml @@ -0,0 +1,9 @@ + + + + + + + diff --git a/AppleWirelessKeyboard/Glyphs/PlayPause.xaml.cs b/AppleWirelessKeyboard/Glyphs/PlayPause.xaml.cs new file mode 100644 index 0000000..3b90f98 --- /dev/null +++ b/AppleWirelessKeyboard/Glyphs/PlayPause.xaml.cs @@ -0,0 +1,27 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Data; +using System.Windows.Documents; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Imaging; +using System.Windows.Navigation; +using System.Windows.Shapes; + +namespace AppleWirelessKeyboard.Glyphs +{ + /// + /// Interaction logic for Play.xaml + /// + public partial class PlayPause : UserControl + { + public PlayPause() + { + InitializeComponent(); + } + } +} diff --git a/AppleWirelessKeyboard/Glyphs/Previous.xaml b/AppleWirelessKeyboard/Glyphs/Previous.xaml new file mode 100644 index 0000000..8095ba6 --- /dev/null +++ b/AppleWirelessKeyboard/Glyphs/Previous.xaml @@ -0,0 +1,8 @@ + + + + + + diff --git a/AppleWirelessKeyboard/Glyphs/Previous.xaml.cs b/AppleWirelessKeyboard/Glyphs/Previous.xaml.cs new file mode 100644 index 0000000..e6b3804 --- /dev/null +++ b/AppleWirelessKeyboard/Glyphs/Previous.xaml.cs @@ -0,0 +1,27 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Data; +using System.Windows.Documents; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Imaging; +using System.Windows.Navigation; +using System.Windows.Shapes; + +namespace AppleWirelessKeyboard.Glyphs +{ + /// + /// Interaction logic for Previous.xaml + /// + public partial class Previous : UserControl + { + public Previous() + { + InitializeComponent(); + } + } +} diff --git a/AppleWirelessKeyboard/Glyphs/PrintScreen.xaml b/AppleWirelessKeyboard/Glyphs/PrintScreen.xaml new file mode 100644 index 0000000..3e52ffd --- /dev/null +++ b/AppleWirelessKeyboard/Glyphs/PrintScreen.xaml @@ -0,0 +1,15 @@ + + + + + + + + + + + + + diff --git a/AppleWirelessKeyboard/Glyphs/PrintScreen.xaml.cs b/AppleWirelessKeyboard/Glyphs/PrintScreen.xaml.cs new file mode 100644 index 0000000..e84c6aa --- /dev/null +++ b/AppleWirelessKeyboard/Glyphs/PrintScreen.xaml.cs @@ -0,0 +1,27 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Data; +using System.Windows.Documents; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Imaging; +using System.Windows.Navigation; +using System.Windows.Shapes; + +namespace AppleWirelessKeyboard.Glyphs +{ + /// + /// Interaction logic for PrintScreen.xaml + /// + public partial class PrintScreen : UserControl + { + public PrintScreen() + { + InitializeComponent(); + } + } +} diff --git a/AppleWirelessKeyboard/Glyphs/TaskManager.xaml b/AppleWirelessKeyboard/Glyphs/TaskManager.xaml new file mode 100644 index 0000000..00cf0f8 --- /dev/null +++ b/AppleWirelessKeyboard/Glyphs/TaskManager.xaml @@ -0,0 +1,10 @@ + + + + + + + + diff --git a/AppleWirelessKeyboard/Glyphs/TaskManager.xaml.cs b/AppleWirelessKeyboard/Glyphs/TaskManager.xaml.cs new file mode 100644 index 0000000..03ac6b9 --- /dev/null +++ b/AppleWirelessKeyboard/Glyphs/TaskManager.xaml.cs @@ -0,0 +1,27 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Data; +using System.Windows.Documents; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Imaging; +using System.Windows.Navigation; +using System.Windows.Shapes; + +namespace AppleWirelessKeyboard.Glyphs +{ + /// + /// Interaction logic for TaskManager.xaml + /// + public partial class TaskManager : UserControl + { + public TaskManager() + { + InitializeComponent(); + } + } +} diff --git a/AppleWirelessKeyboard/Glyphs/VolumeOff.xaml b/AppleWirelessKeyboard/Glyphs/VolumeOff.xaml new file mode 100644 index 0000000..de7613f --- /dev/null +++ b/AppleWirelessKeyboard/Glyphs/VolumeOff.xaml @@ -0,0 +1,14 @@ + + + + + + + + diff --git a/AppleWirelessKeyboard/Glyphs/VolumeOff.xaml.cs b/AppleWirelessKeyboard/Glyphs/VolumeOff.xaml.cs new file mode 100644 index 0000000..1d6b117 --- /dev/null +++ b/AppleWirelessKeyboard/Glyphs/VolumeOff.xaml.cs @@ -0,0 +1,27 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Data; +using System.Windows.Documents; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Imaging; +using System.Windows.Navigation; +using System.Windows.Shapes; + +namespace AppleWirelessKeyboard.Glyphs +{ + /// + /// Interaction logic for VolumeOff.xaml + /// + public partial class VolumeOff : UserControl + { + public VolumeOff() + { + InitializeComponent(); + } + } +} diff --git a/AppleWirelessKeyboard/Glyphs/VolumeOn.xaml b/AppleWirelessKeyboard/Glyphs/VolumeOn.xaml new file mode 100644 index 0000000..272a999 --- /dev/null +++ b/AppleWirelessKeyboard/Glyphs/VolumeOn.xaml @@ -0,0 +1,17 @@ + + + + + + + + + + + diff --git a/AppleWirelessKeyboard/Glyphs/VolumeOn.xaml.cs b/AppleWirelessKeyboard/Glyphs/VolumeOn.xaml.cs new file mode 100644 index 0000000..a4e3119 --- /dev/null +++ b/AppleWirelessKeyboard/Glyphs/VolumeOn.xaml.cs @@ -0,0 +1,27 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Data; +using System.Windows.Documents; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Imaging; +using System.Windows.Navigation; +using System.Windows.Shapes; + +namespace AppleWirelessKeyboard.Glyphs +{ + /// + /// Interaction logic for VolumeOn.xaml + /// + public partial class VolumeOn : UserControl + { + public VolumeOn() + { + InitializeComponent(); + } + } +} diff --git a/AppleWirelessKeyboard/Gnome-Preferences-Desktop-Keyboard-Shortcuts.ico b/AppleWirelessKeyboard/Gnome-Preferences-Desktop-Keyboard-Shortcuts.ico new file mode 100644 index 0000000000000000000000000000000000000000..1daeb1445642c215c87337e3ede9981f9cba7507 GIT binary patch literal 34499 zcmeHw2UwLy*6_`S3nsfU#dK3l*-hCmo5Yx`u^SVWYGTEL8f$EbVnK@Z-h1!8cSMvX zqJUKCB2_wyioG!BKWFZ}cts_)-T!;O$Ln*PdFMSd@0_Wp%^(mwClCr|%n)EWPVo6p z0>NT|K=92sqUVUe3k3TyZQMB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+ /// Win32 import information for use with the Wiimote library + /// + class HIDImports + { + // + // Flags controlling what is included in the device information set built + // by SetupDiGetClassDevs + // + public const int DIGCF_DEFAULT = 0x00000001; // only valid with DIGCF_DEVICEINTERFACE + public const int DIGCF_PRESENT = 0x00000002; + public const int DIGCF_ALLCLASSES = 0x00000004; + public const int DIGCF_PROFILE = 0x00000008; + public const int DIGCF_DEVICEINTERFACE = 0x00000010; + + [Flags] + public enum EFileAttributes : uint + { + Readonly = 0x00000001, + Hidden = 0x00000002, + System = 0x00000004, + Directory = 0x00000010, + Archive = 0x00000020, + Device = 0x00000040, + Normal = 0x00000080, + Temporary = 0x00000100, + SparseFile = 0x00000200, + ReparsePoint = 0x00000400, + Compressed = 0x00000800, + Offline = 0x00001000, + NotContentIndexed = 0x00002000, + Encrypted = 0x00004000, + Write_Through = 0x80000000, + Overlapped = 0x40000000, + NoBuffering = 0x20000000, + RandomAccess = 0x10000000, + SequentialScan = 0x08000000, + DeleteOnClose = 0x04000000, + BackupSemantics = 0x02000000, + PosixSemantics = 0x01000000, + OpenReparsePoint = 0x00200000, + OpenNoRecall = 0x00100000, + FirstPipeInstance = 0x00080000 + } + + [StructLayout(LayoutKind.Sequential)] + public struct SP_DEVINFO_DATA + { + public uint cbSize; + public Guid ClassGuid; + public uint DevInst; + public IntPtr Reserved; + } + + [StructLayout(LayoutKind.Sequential)] + public struct SP_DEVICE_INTERFACE_DATA + { + public int cbSize; + public Guid InterfaceClassGuid; + public int Flags; + public IntPtr RESERVED; + } + + [StructLayout(LayoutKind.Sequential, Pack = 1)] + public struct SP_DEVICE_INTERFACE_DETAIL_DATA + { + public UInt32 cbSize; + [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 256)] + public string DevicePath; + } + + [StructLayout(LayoutKind.Sequential)] + public struct HIDD_ATTRIBUTES + { + public int Size; + public short VendorID; + public short ProductID; + public short VersionNumber; + } + + [DllImport(@"hid.dll", CharSet = CharSet.Auto, SetLastError = true)] + public static extern void HidD_GetHidGuid(out Guid gHid); + + [DllImport("hid.dll")] + public static extern Boolean HidD_GetAttributes(IntPtr HidDeviceObject, ref HIDD_ATTRIBUTES Attributes); + + [DllImport("hid.dll")] + internal extern static bool HidD_SetOutputReport( + IntPtr HidDeviceObject, + byte[] lpReportBuffer, + uint ReportBufferLength); + + [DllImport(@"setupapi.dll", CharSet = CharSet.Auto, SetLastError = true)] + public static extern IntPtr SetupDiGetClassDevs( + ref Guid ClassGuid, + [MarshalAs(UnmanagedType.LPTStr)] string Enumerator, + IntPtr hwndParent, + UInt32 Flags + ); + + [DllImport(@"setupapi.dll", CharSet = CharSet.Auto, SetLastError = true)] + public static extern Boolean SetupDiEnumDeviceInterfaces( + IntPtr hDevInfo, + //ref SP_DEVINFO_DATA devInfo, + IntPtr devInvo, + ref Guid interfaceClassGuid, + Int32 memberIndex, + ref SP_DEVICE_INTERFACE_DATA deviceInterfaceData + ); + + [DllImport(@"setupapi.dll", SetLastError = true)] + public static extern Boolean SetupDiGetDeviceInterfaceDetail( + IntPtr hDevInfo, + ref SP_DEVICE_INTERFACE_DATA deviceInterfaceData, + IntPtr deviceInterfaceDetailData, + UInt32 deviceInterfaceDetailDataSize, + out UInt32 requiredSize, + IntPtr deviceInfoData + ); + + [DllImport(@"setupapi.dll", SetLastError = true)] + public static extern Boolean SetupDiGetDeviceInterfaceDetail( + IntPtr hDevInfo, + ref SP_DEVICE_INTERFACE_DATA deviceInterfaceData, + ref SP_DEVICE_INTERFACE_DETAIL_DATA deviceInterfaceDetailData, + UInt32 deviceInterfaceDetailDataSize, + out UInt32 requiredSize, + IntPtr deviceInfoData + ); + + [DllImport(@"setupapi.dll", CharSet = CharSet.Auto, SetLastError = true)] + public static extern UInt16 SetupDiDestroyDeviceInfoList(IntPtr hDevInfo); + + [DllImport("Kernel32.dll", SetLastError = true, CharSet = CharSet.Auto)] + public static extern SafeFileHandle CreateFile( + string fileName, + [MarshalAs(UnmanagedType.U4)] FileAccess fileAccess, + [MarshalAs(UnmanagedType.U4)] FileShare fileShare, + IntPtr securityAttributes, + [MarshalAs(UnmanagedType.U4)] FileMode creationDisposition, + [MarshalAs(UnmanagedType.U4)] EFileAttributes flags, + IntPtr template); + + [DllImport("kernel32.dll", SetLastError = true)] + [return: MarshalAs(UnmanagedType.Bool)] + public static extern bool CloseHandle(IntPtr hObject); + + [DllImport("setupapi.dll", CharSet = CharSet.Auto, SetLastError = true)] + public static extern bool SetupDiGetDeviceRegistryProperty( + IntPtr DeviceInfoSet, + ref SP_DEVINFO_DATA DeviceInfoData, + uint Property, + out UInt32 PropertyRegDataType, + IntPtr PropertyBuffer, + uint PropertyBufferSize, + out UInt32 RequiredSize); + + public enum SPDRP + { + SPDRP_DEVICEDESC = 0x00000000, + SPDRP_HARDWAREID = 0x00000001, + SPDRP_COMPATIBLEIDS = 0x00000002, + SPDRP_NTDEVICEPATHS = 0x00000003, + SPDRP_SERVICE = 0x00000004, + SPDRP_CONFIGURATION = 0x00000005, + SPDRP_CONFIGURATIONVECTOR = 0x00000006, + SPDRP_CLASS = 0x00000007, + SPDRP_CLASSGUID = 0x00000008, + SPDRP_DRIVER = 0x00000009, + SPDRP_CONFIGFLAGS = 0x0000000A, + SPDRP_MFG = 0x0000000B, + SPDRP_FRIENDLYNAME = 0x0000000C, + SPDRP_LOCATION_INFORMATION = 0x0000000D, + SPDRP_PHYSICAL_DEVICE_OBJECT_NAME = 0x0000000E, + SPDRP_CAPABILITIES = 0x0000000F, + SPDRP_UI_NUMBER = 0x00000010, + SPDRP_UPPERFILTERS = 0x00000011, + SPDRP_LOWERFILTERS = 0x00000012, + SPDRP_MAXIMUM_PROPERTY = 0x00000013, + } + + [DllImport("setupapi.dll", SetLastError = true)] + public static extern bool SetupDiEnumDeviceInfo(IntPtr DeviceInfoSet, uint MemberIndex, ref SP_DEVINFO_DATA DeviceInfoData); + } +} diff --git a/AppleWirelessKeyboard/IoControl.cs b/AppleWirelessKeyboard/IoControl.cs new file mode 100644 index 0000000..cff6161 --- /dev/null +++ b/AppleWirelessKeyboard/IoControl.cs @@ -0,0 +1,67 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Runtime.InteropServices; +using System.IO; +using System.Threading.Tasks; + +namespace AppleWirelessKeyboard +{ + public static class IoControl + { + #region DeviceIoControl + const int OPEN_EXISTING = 3; + const uint GENERIC_READ = 0x80000000; + const uint GENERIC_WRITE = 0x40000000; + const uint FILE_SHARE_WRITE = 0x00000002; + const uint IOCTL_STORAGE_EJECT_MEDIA = 2967560; + + [DllImport("kernel32")] + private static extern IntPtr CreateFile + (string filename, uint desiredAccess, + uint shareMode, IntPtr securityAttributes, + int creationDisposition, int flagsAndAttributes, + IntPtr templateFile); + + [DllImport("kernel32")] + private static extern int DeviceIoControl + (IntPtr deviceHandle, uint ioControlCode, + IntPtr inBuffer, int inBufferSize, + IntPtr outBuffer, int outBufferSize, + ref int bytesReturned, IntPtr overlapped); + + [DllImport("kernel32")] + private static extern int CloseHandle(IntPtr handle); + #endregion + + public static void EjectMedia(char driveLetter) + { + try + { + string path = "\\\\.\\" + driveLetter + ":"; + IntPtr handle = CreateFile(path, GENERIC_READ, FILE_SHARE_WRITE, IntPtr.Zero, OPEN_EXISTING, 0, IntPtr.Zero); + if ((long)handle == -1) + { + throw new IOException("Unable to open drive " + driveLetter); + } + int dummy = 0; + DeviceIoControl(handle, IOCTL_STORAGE_EJECT_MEDIA, IntPtr.Zero, 0, IntPtr.Zero, 0, ref dummy, IntPtr.Zero); + CloseHandle(handle); + } + catch { } + } + public static void EjectAllMedia() + { + Task.Factory.StartNew(() => + { + NotificationCenter.NotifyEject(); + foreach (DriveInfo drive in DriveInfo.GetDrives()) + if (drive.DriveType == DriveType.CDRom) + { + EjectMedia(drive.Name[0]); + } + }); + } + } +} diff --git a/AppleWirelessKeyboard/KeyboardControl.cs b/AppleWirelessKeyboard/KeyboardControl.cs new file mode 100644 index 0000000..4baff7e --- /dev/null +++ b/AppleWirelessKeyboard/KeyboardControl.cs @@ -0,0 +1,172 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Runtime.InteropServices; +using System.Diagnostics; +using System.Windows.Input; +using System.Threading; +using System.Threading.Tasks; + +namespace AppleWirelessKeyboard +{ + public static class KeyboardControl + { + const int VK_SNAPSHOT = 44; + const int VK_DELETE = 46; + const int VK_MEDIA_NEXT_TRACK = 176; + const int VK_MEDIA_PREV_TRACK = 177; + const int VK_MEDIA_STOP = 178; + const int VK_MEDIA_PLAY_PAUSE = 179; + const int VK_END = 37; + const int VK_HOME = 36; + const int VK_PAGEUP = 33; + const int VK_PAGEDOWN = 35; + const int VK_F3 = 117; + const int VK_INSERT = 45; + + public static void Send(int VKey, KeyboardEvent e = KeyboardEvent.Both) + { + switch (e) + { + case KeyboardEvent.Both: + { + keybd_event((byte)VKey, 0, 0, 0); + keybd_event((byte)VKey, 0, 2, 0); + } + break; + case KeyboardEvent.Down: + keybd_event((byte)VKey, 0, 0, 0); + break; + case KeyboardEvent.Up: + keybd_event((byte)VKey, 0, 2, 0); + break; + } + } + + public static void SendInsert() + { + Task.Factory.StartNew(() => + { + Send(VK_INSERT); + }); + } + + public static void SendDelete() + { + Task.Factory.StartNew(() => + { + Send(VK_DELETE); + }); + } + + public static void SendPrintScreen() + { + Task.Factory.StartNew(() => + { + Send(VK_SNAPSHOT); + Thread.Sleep(100); + NotificationCenter.NotifyPrintScreen(); + }); + } + + public static void SendPlayPause() + { + Task.Factory.StartNew(() => + { + if (iTunesControl.iTunesRunning) + iTunesControl.PlayPause(); + else + Send(VK_MEDIA_PLAY_PAUSE); + NotificationCenter.NotifyPlayPause(); + }); + } + + public static void SendNextTrack() + { + Task.Factory.StartNew(() => + { + if (iTunesControl.iTunesRunning) + iTunesControl.NextSong(); + else + Send(VK_MEDIA_NEXT_TRACK); + NotificationCenter.NotifyNext(); + }); + } + + public static void SendPreviousTrack() + { + Task.Factory.StartNew(() => + { + if (iTunesControl.iTunesRunning) + iTunesControl.PreviousSong(); + else + Send(VK_MEDIA_PREV_TRACK); + NotificationCenter.NotifyPrevious(); + }); + } + + public static void OpenTaskManager() + { + Task.Factory.StartNew(() => + { + Process taskmgr = Process.GetProcessesByName("taskmgr.exe").FirstOrDefault(); + if (taskmgr != null) + SetForegroundWindow(taskmgr.MainWindowHandle); + else + Process.Start("taskmgr.exe"); + NotificationCenter.NotifyTaskManager(); + }); + } + + #region PInvoke + [DllImport("user32.dll")] + static extern bool SetForegroundWindow(IntPtr hWnd); + + [DllImport("user32.dll")] + static extern void keybd_event(byte bVk, byte bScan, uint dwFlags, int dwExtraInfo); + + public enum KeyboardEvent + { + Down = 0, Up = 2, Both + } + #endregion + + public static void SendPageUp() + { + Task.Factory.StartNew(() => + { + Send(VK_PAGEUP); + }); + } + public static void SendPageDown() + { + Task.Factory.StartNew(() => + { + Send(VK_PAGEDOWN); + }); + } + public static void SendHome() + { + Task.Factory.StartNew(() => + { + Send(VK_HOME); + }); + } + public static void SendEnd() + { + Task.Factory.StartNew(() => + { + Send(VK_END); + }); + } + + public static void SendF3() + { + Task.Factory.StartNew(() => + { + Send(VK_F3); + }); + } + } +} diff --git a/AppleWirelessKeyboard/KeyboardHandler.cs b/AppleWirelessKeyboard/KeyboardHandler.cs new file mode 100644 index 0000000..8686f30 --- /dev/null +++ b/AppleWirelessKeyboard/KeyboardHandler.cs @@ -0,0 +1,168 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Windows.Input; +using System.Threading.Tasks; +using System.Threading; +using System.Windows; + +namespace AppleWirelessKeyboard +{ + public static class KeyboardHandler + { + static KeyboardHandler() + { + PowerButtonPressCount = 0; + } + public static bool FMode + { + get + { + return AppleWirelessKeyboard.Properties.Settings.Default.FMode; + } + set + { + if (AppleWirelessKeyboard.Properties.Settings.Default.FMode != value) + { + AppleWirelessKeyboard.Properties.Settings.Default.FMode = value; + if (value) + NotificationCenter.NotifyOn(); + else NotificationCenter.NotifyOff(); + } + } + } + + public static void HandleEject() + { + if (!AppleKeyboardHID2.FnDown) + FMode = !FMode; + else IoControl.EjectAllMedia(); + } + + public static bool HandleKeyDown(KeyboardListener.KeyHookEventArgs e) + { + bool F = (FMode || e.ModifierFn) && !e.ModifierAnyNative; + + switch (e.Key) + { + case Key.F3: + if (F) + { + KeyboardControl.SendPrintScreen(); + return true; + } + break; + case Key.F4: + if (F) + { + KeyboardControl.OpenTaskManager(); + return true; + } + break; + case Key.F2: + if (F) + { + KeyboardControl.SendF3(); + return true; + } + break; + case Key.F7: + if (F) + { + KeyboardControl.SendPreviousTrack(); + return true; + } + break; + case Key.F8: + if (F) + { + KeyboardControl.SendPlayPause(); + return true; + } + break; + case Key.F9: + if (F) + { + KeyboardControl.SendNextTrack(); + return true; + } + break; + case Key.F10: + if (F) + { + VolumeControl.ToggleMute(); + return true; + } + break; + case Key.F11: + if (F) + { + VolumeControl.VolumeDown(); + return true; + } + break; + case Key.F12: + if (F) + { + VolumeControl.VolumeUp(); + return true; + } + break; + case Key.Back: + if (e.ModifierFn) + { + KeyboardControl.SendDelete(); + return true; + } + break; + case Key.Up: + if (e.ModifierFn) + { + KeyboardControl.SendPageUp(); + return true; + } + break; + case Key.Down: + if (e.ModifierFn) + { + KeyboardControl.SendPageDown(); + return true; + } + break; + case Key.Left: + if(e.ModifierFn) + { + KeyboardControl.SendHome(); + return true; + } + break; + case Key.Right: + if (e.ModifierFn) + { + KeyboardControl.SendEnd(); + return true; + } + break; + case Key.Enter: + if (e.ModifierFn) + { + KeyboardControl.SendInsert(); + return true; + } + break; + } + + if (e.ModifierAnyAlt && (FMode || e.ModifierFn)) + if (e.Key == Key.F3) + { + KeyboardControl.SendPrintScreen(); + return true; + } + + return false; + } + public static int PowerButtonPressCount { get; set; } + + } +} diff --git a/AppleWirelessKeyboard/KeyboardListener.cs b/AppleWirelessKeyboard/KeyboardListener.cs new file mode 100644 index 0000000..5ec7d26 --- /dev/null +++ b/AppleWirelessKeyboard/KeyboardListener.cs @@ -0,0 +1,210 @@ +using System; +using System.Collections.Generic; +using System.Text; +using System.Runtime.InteropServices; +using System.Windows.Input; +using System.Diagnostics; +using System.Windows; + +namespace AppleWirelessKeyboard +{ + /// + /// A class that manages a global low level keyboard hook + /// + public static class KeyboardListener + { + static KeyboardListener() + { + HookedKeys = new List(); + Hook = IntPtr.Zero; + } + #region PInvoke Structures + public delegate int keyboardHookProc(int code, int wParam, ref keyboardHookStruct lParam); + + public struct keyboardHookStruct + { + public int vkCode; + public int scanCode; + public int flags; + public int time; + public int dwExtraInfo; + } + + private const int WH_KEYBOARD_LL = 13; + private const int WM_KEYDOWN = 0x100; + private const int WM_KEYUP = 0x101; + private const int WM_SYSKEYDOWN = 0x104; + private const int WM_SYSKEYUP = 0x105; + #endregion + + #region Public declarations + + public static List HookedKeys { get; set; } + internal static IntPtr Hook { get; set; } + + public static event KeyHookEventHandler KeyDown; + public static event KeyHookEventHandler KeyUp; + + public static bool ModifierLeftAlt { get; set; } + public static bool ModifierRightAlt { get; set; } + public static bool ModifierLeftCtrl { get; set; } + public static bool ModifierRightCtrl { get; set; } + public static bool ModifierLeftShift { get; set; } + public static bool ModifierRightShift { get; set; } + public static bool ModifierLeftWin { get; set; } + public static bool ModifierRightWin { get; set; } + public static bool ModifierCapsLock { get; set; } + public static bool ModifierFn { get; set; } + + public class KeyHookEventArgs + { + public KeyHookEventArgs() + { + } + public Key Key { get; set; } + public bool ModifierLeftAlt { get; set; } + public bool ModifierRightAlt { get; set; } + public bool ModifierLeftCtrl { get; set; } + public bool ModifierRightCtrl { get; set; } + public bool ModifierLeftShift { get; set; } + public bool ModifierRightShift { get; set; } + public bool ModifierLeftWin { get; set; } + public bool ModifierRightWin { get; set; } + public bool ModifierCapsLock { get; set; } + public bool ModifierFn { get; set; } + + public bool ModifierAnyAlt { get { return ModifierLeftAlt || ModifierRightAlt; } set { ModifierLeftAlt = value; } } + public bool ModifierAnyCtrl { get { return ModifierLeftCtrl || ModifierRightCtrl; } set { ModifierLeftCtrl = value; } } + public bool ModifierAnyShift { get { return ModifierLeftShift || ModifierRightShift; } set { ModifierLeftShift = value; } } + public bool ModifierAnyWin { get { return ModifierLeftWin || ModifierRightWin; } set { ModifierLeftWin = value; } } + + public bool ModifierAnyNative { get { return (((ModifierAnyAlt) || (ModifierAnyWin)) || ((ModifierAnyCtrl) || (ModifierAnyShift))); } } + public bool ModifierAny { get { return ((ModifierAny) || (ModifierFn)); } } + } + + public delegate bool KeyHookEventHandler(KeyHookEventArgs e); + #endregion + + #region Public Methods + + internal static void SetModifiers(Key key, bool IsPressed, int VKey) + { + switch (key) + { + case Key.LeftAlt: + ModifierLeftAlt = IsPressed; + break; + case Key.RightAlt: + ModifierRightAlt = IsPressed; + break; + case Key.RightCtrl: + ModifierRightCtrl = IsPressed; + break; + case Key.LeftCtrl: + ModifierLeftCtrl = IsPressed; + break; + case Key.LeftShift: + ModifierLeftShift = IsPressed; + break; + case Key.RightShift: + ModifierRightShift = IsPressed; + break; + case Key.CapsLock: + ModifierCapsLock = IsPressed; + break; + case Key.LWin: + ModifierLeftWin = IsPressed; + break; + case Key.RWin: + ModifierRightWin = IsPressed; + break; + } + if (!AppleKeyboardHID2.Registered) + AppleKeyboardHID2.Start(); + } + internal static KeyHookEventArgs CreateEventArgs(Key key) + { + return new KeyHookEventArgs() + { + Key = key, + ModifierCapsLock = ModifierCapsLock, + ModifierLeftAlt = ModifierLeftAlt, + ModifierRightAlt = ModifierRightAlt, + ModifierLeftCtrl = ModifierLeftCtrl, + ModifierRightCtrl = ModifierRightCtrl, + ModifierLeftShift = ModifierLeftShift, + ModifierRightShift = ModifierRightShift, + ModifierLeftWin = ModifierLeftWin, + ModifierRightWin = ModifierRightWin, + ModifierFn = ModifierFn + }; + } + + public static keyboardHookProc HookProcessor { get; set; } + + public static void Register() + { + HookProcessor = Hook_Callback; + IntPtr hInstance = GetModuleHandle(Process.GetCurrentProcess().MainModule.ModuleName); + Hook = SetWindowsHookEx(WH_KEYBOARD_LL, HookProcessor, hInstance, 0); + } + + public static void UnRegister() + { + UnhookWindowsHookEx(Hook); + } + + public static bool TriggerKeyDown(KeyHookEventArgs args) + { + if (KeyDown != null) + return KeyDown(args); + else return false; + } + public static bool TriggerKeyUp(KeyHookEventArgs args) + { + if (KeyUp != null) + return KeyUp(args); + else return false; + } + public static int Hook_Callback(int code, int wParam, ref keyboardHookStruct lParam) + { + if (code >= 0) + { + Key key = (Key)System.Windows.Input.KeyInterop.KeyFromVirtualKey(lParam.vkCode); + bool IsPressed = (wParam == WM_KEYDOWN || wParam == WM_SYSKEYDOWN); + + SetModifiers(key, IsPressed, lParam.vkCode); + if (HookedKeys.Contains(key)) + { + KeyHookEventArgs kea = CreateEventArgs(key); + + bool Handled = false; + if (IsPressed) + Handled = TriggerKeyDown(kea); + else + Handled = TriggerKeyUp(kea); + + if (Handled) + return 1; + } + } + return CallNextHookEx(Hook, code, wParam, ref lParam); + } + #endregion + + #region DLL imports + [DllImport("user32.dll")] + static extern IntPtr SetWindowsHookEx(int idHook, keyboardHookProc callback, IntPtr hInstance, uint threadId); + + [DllImport("user32.dll")] + static extern bool UnhookWindowsHookEx(IntPtr hInstance); + + [DllImport("user32.dll")] + static extern int CallNextHookEx(IntPtr idHook, int nCode, int wParam, ref keyboardHookStruct lParam); + + [DllImport("kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)] + public static extern IntPtr GetModuleHandle(string lpModuleName); + + #endregion + } +} diff --git a/AppleWirelessKeyboard/MainWindow.xaml b/AppleWirelessKeyboard/MainWindow.xaml new file mode 100644 index 0000000..6f6d9b0 --- /dev/null +++ b/AppleWirelessKeyboard/MainWindow.xaml @@ -0,0 +1,15 @@ + + + + + + + + + + + diff --git a/AppleWirelessKeyboard/MainWindow.xaml.cs b/AppleWirelessKeyboard/MainWindow.xaml.cs new file mode 100644 index 0000000..28760de --- /dev/null +++ b/AppleWirelessKeyboard/MainWindow.xaml.cs @@ -0,0 +1,60 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Data; +using System.Windows.Documents; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Imaging; +using System.Windows.Navigation; +using System.Windows.Shapes; +using System.Windows.Media.Animation; + +namespace AppleWirelessKeyboard +{ + /// + /// Interaction logic for MainWindow.xaml + /// + public partial class MainWindow : Window + { + public MainWindow() + { + InitializeComponent(); + } + public void ShowOff(Control glyph, bool valueBar = false, int value = 0) + { + this.DataContext = new { Glyph = glyph }; + + if (valueBar) ValueBar.Visibility = System.Windows.Visibility.Visible; + else ValueBar.Visibility = System.Windows.Visibility.Collapsed; + + MakeValue(value); + + this.Show(); + + DoubleAnimationUsingKeyFrames Fade = new DoubleAnimationUsingKeyFrames(); + Fade.Duration = new Duration(TimeSpan.FromSeconds(1)); + Fade.KeyFrames.Add(new LinearDoubleKeyFrame(1, KeyTime.FromPercent(0))); + Fade.KeyFrames.Add(new LinearDoubleKeyFrame(1, KeyTime.FromPercent(0.5))); + Fade.KeyFrames.Add(new LinearDoubleKeyFrame(0, KeyTime.FromPercent(1))); + BeginAnimation(OpacityProperty, Fade); + } + public void MakeValue(int value) + { + ValueBar.Children.Clear(); + + for (int i = 0; i <= value; i++) + { + Rectangle rect = new Rectangle(); + rect.Fill = new SolidColorBrush(Colors.White); + rect.Width = 6; + rect.Height = 6; + rect.Margin = new Thickness(0, 0, 3, 0); + ValueBar.Children.Add(rect); + } + } + } +} diff --git a/AppleWirelessKeyboard/NotificationCenter.cs b/AppleWirelessKeyboard/NotificationCenter.cs new file mode 100644 index 0000000..6edc57c --- /dev/null +++ b/AppleWirelessKeyboard/NotificationCenter.cs @@ -0,0 +1,100 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace AppleWirelessKeyboard +{ + public static class NotificationCenter + { + static NotificationCenter() + { + + } + public static void NotifyMuteOn() + { + App.Window.Dispatcher.Invoke(new Action(delegate + { + App.Window.ShowOff(new Glyphs.MuteOn()); + })); + } + public static void NotifyMuteOff() + { + App.Window.Dispatcher.Invoke(new Action(delegate + { + App.Window.ShowOff(new Glyphs.MuteOff()); + })); + } + public static void NotifyNoVolume() + { + App.Window.Dispatcher.Invoke(new Action(delegate + { + App.Window.ShowOff(new Glyphs.VolumeOff()); + })); + } + public static void NotifyVolumeLevel(int level)//1-16 + { + App.Window.Dispatcher.Invoke(new Action(delegate + { + App.Window.ShowOff(new Glyphs.VolumeOn(), true, level); + })); + } + public static void NotifyTaskManager() + { + App.Window.Dispatcher.Invoke((Action)delegate + { + App.Window.ShowOff(new Glyphs.TaskManager()); + }); + } + public static void NotifyPrintScreen() + { + App.Window.Dispatcher.Invoke((Action)delegate + { + App.Window.ShowOff(new Glyphs.PrintScreen()); + }); + } + public static void NotifyOn() + { + App.Window.Dispatcher.Invoke((Action)delegate + { + App.Window.ShowOff(new Glyphs.On()); + }); + } + public static void NotifyOff() + { + App.Window.Dispatcher.Invoke((Action)delegate + { + App.Window.ShowOff(new Glyphs.Off()); + }); + } + public static void NotifyPlayPause() + { + App.Window.Dispatcher.Invoke((Action)delegate + { + App.Window.ShowOff(new Glyphs.PlayPause()); + }); + } + public static void NotifyPrevious() + { + App.Window.Dispatcher.Invoke((Action)delegate + { + App.Window.ShowOff(new Glyphs.Previous()); + }); + } + public static void NotifyNext() + { + App.Window.Dispatcher.Invoke((Action)delegate + { + App.Window.ShowOff(new Glyphs.Next()); + }); + } + + internal static void NotifyEject() + { + App.Window.Dispatcher.Invoke((Action)delegate + { + App.Window.ShowOff(new Glyphs.Eject()); + }); + } + } +} diff --git a/AppleWirelessKeyboard/PowerControl.cs b/AppleWirelessKeyboard/PowerControl.cs new file mode 100644 index 0000000..7d2739c --- /dev/null +++ b/AppleWirelessKeyboard/PowerControl.cs @@ -0,0 +1,41 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Runtime.InteropServices; +using System.Diagnostics; +using System.Threading.Tasks; +using System.Threading; +using System.Windows; + +namespace AppleWirelessKeyboard +{ + public class PowerControl + { + public static void Hibernate() + { + Task.Factory.StartNew(() => + { + if (PowerStatusBox.PowerAction("Hibernate", 10)) + SetSuspendState(true, true, true); + }); + } + + public static void Shutdown() + { + Task.Factory.StartNew(() => + { + if (PowerStatusBox.PowerAction("Shut Down", 10)) + { + ProcessStartInfo si = new ProcessStartInfo("shutdown", "/s /t 0"); + si.CreateNoWindow = true; + si.WindowStyle = ProcessWindowStyle.Hidden; + Process.Start(si); + } + }); + } + + [DllImport("powrprof.dll", SetLastError = true)] + static extern bool SetSuspendState(bool hibernate, bool forceCritical, bool disableWakeEvent); + } +} diff --git a/AppleWirelessKeyboard/PowerStatusBox.xaml b/AppleWirelessKeyboard/PowerStatusBox.xaml new file mode 100644 index 0000000..b3a7c45 --- /dev/null +++ b/AppleWirelessKeyboard/PowerStatusBox.xaml @@ -0,0 +1,16 @@ + + + + + + + + +