-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
38ebdcc
commit c0368b3
Showing
11 changed files
with
2,833 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<?xml version="1.0" encoding="utf-8" ?> | ||
<configuration> | ||
<startup> | ||
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" /> | ||
</startup> | ||
</configuration> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
namespace MediaButtonsSend | ||
{ | ||
public enum AppCommandValues | ||
{ | ||
BrowserBack = 1, | ||
BrowserForward = 2, | ||
BrowserRefresh = 3, | ||
BrowserStop = 4, | ||
BrowserSearch = 5, | ||
BrowserFavorite = 6, | ||
BrowserHome = 7, | ||
VolumeMute = 8, | ||
VolumeDown = 9, | ||
VolumeUp = 10, | ||
MediaNext = 11, | ||
MediaPrevious = 12, | ||
MediaStop = 13, | ||
MediaPlayPause = 14, | ||
LaunchMail = 15, | ||
LaunchMediaSelect = 16, | ||
LaunchApp1 = 17, | ||
LaunchApp2 = 18, | ||
BassDown = 19, | ||
BassBoost = 20, | ||
BassUp = 21, | ||
TrebleUp = 22, | ||
TrebleDown = 23, | ||
MicrophoneMute = 24, | ||
MicrophoneVolumeUp = 25, | ||
MicrophoneVolumeDown = 26, | ||
Help = 27, | ||
Find = 28, | ||
New = 29, | ||
Open = 30, | ||
Close = 31, | ||
Save = 32, | ||
Print = 33, | ||
Undo = 34, | ||
Redo = 35, | ||
Copy = 36, | ||
Cut = 37, | ||
Paste = 38, | ||
ReplyToMail = 39, | ||
ForwardMail = 40, | ||
SendMail = 41, | ||
SpellCheck = 42, | ||
Dictate = 43, | ||
MicrophoneOnOff = 44, | ||
CorrectionList = 45, | ||
MediaPlay = 46, | ||
MediaPause = 47, | ||
MediaRecord = 48, | ||
MediaFastForward = 49, | ||
MediaRewind = 50, | ||
MediaChannelUp = 51, | ||
MediaChannelDown = 52, | ||
Delete = 53, | ||
Flip3D = 54 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
using System; | ||
using System.Runtime.InteropServices; | ||
using System.Threading; | ||
using System.Windows.Forms; | ||
|
||
namespace MediaButtonsSend | ||
{ | ||
//http://msdn.microsoft.com/en-us/library/dd375731%28v=VS.85%29.aspx | ||
|
||
public static class AppCommand | ||
{ | ||
private static ManualResetEvent _mre = new ManualResetEvent(false); | ||
private static Form _frm; | ||
|
||
public static void Send(AppCommandValues cmd) | ||
{ | ||
if (_frm == null) Initialize(); | ||
_frm?.Invoke(new MethodInvoker(() => SendMessage(_frm.Handle, WM_APPCOMMAND, _frm.Handle, (IntPtr)((int)cmd << 16)))); | ||
Cleanup(); | ||
} | ||
|
||
private static void Initialize() | ||
{ | ||
// to be able to vork in visual studio (and other similar) running as admin we have to emulate a windows form app. | ||
//the UAC UIPI (User Interface Privilege Isolation) kills our keybd_event when running as admin | ||
// Run the message loop on another thread so we're compatible with a console mode app | ||
var t = new Thread(() => | ||
{ | ||
_frm = new Form | ||
{ | ||
ShowInTaskbar = false, | ||
Visible = false, | ||
}; | ||
|
||
var dummy = _frm.Handle; | ||
_frm.BeginInvoke(new MethodInvoker(() => _mre.Set())); | ||
Application.Run(); | ||
}); | ||
t.SetApartmentState(ApartmentState.STA); | ||
t.IsBackground = true; | ||
t.Start(); | ||
_mre.WaitOne(); | ||
|
||
} | ||
|
||
public static void Cleanup() | ||
{ | ||
if (_frm != null) | ||
{ | ||
_frm.BeginInvoke(new MethodInvoker(() => | ||
{ | ||
_frm.Close(); | ||
Application.ExitThread(); | ||
_mre.Set(); | ||
})); | ||
_mre.WaitOne(); | ||
_frm = null; | ||
} | ||
} | ||
|
||
|
||
|
||
// Pinvoke | ||
private const int WM_APPCOMMAND = 0x319; | ||
[DllImport("user32.dll")] | ||
private static extern IntPtr SendMessage(IntPtr hWnd, int msg, IntPtr wp, IntPtr lp); | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
using System; | ||
using System.Windows.Forms; | ||
|
||
namespace MediaButtonsSend | ||
{ | ||
public partial class FrmHelp : Form | ||
{ | ||
public FrmHelp() | ||
{ | ||
InitializeComponent(); | ||
} | ||
|
||
private void FrmHelp_Load(object sender, EventArgs e) | ||
{ | ||
TxtValues.Text = string.Join(Environment.NewLine, Enum.GetNames(typeof(AppCommandValues))); | ||
} | ||
|
||
private void CmdClose_Click(object sender, EventArgs e) | ||
{ | ||
Close(); | ||
} | ||
} | ||
} |
Oops, something went wrong.