Windows Hotkey control volume
来源:互联网 发布:理财入门知乎 编辑:程序博客网 时间:2024/06/12 00:09
using Microsoft.SqlServer.Server;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace HotkeyTest
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private int second=3;
private int counter;
Image turnOFF = Resource1.OFF;
Image turnON = Resource1.ON;
private const int WM_HOTKEY = 0x312; //窗口消息:热键
private const int WM_CREATE = 0x1; //窗口消息:创建
private const int WM_DESTROY = 0x2; //窗口消息:销毁
private const int HotKeyVOLUME_UPID = 1; //热键ID(自定义)
private const int HotKeyVOLUME_DOWN = 2; //热键ID(自定义)
private const int HotKeyVOLUME_MUTE = 3; //热键ID(自定义)
//音量
[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
static extern IntPtr SendMessage(IntPtr hWnd, uint Msg, uint wParam, uint lParam);
const uint WM_APPCOMMAND = 0x319;
const uint APPCOMMAND_VOLUME_UP = 0x0a;
const uint APPCOMMAND_VOLUME_DOWN = 0x09;
const uint APPCOMMAND_VOLUME_MUTE = 0x08;
//picturebox show time
private void timer1_Tick(object sender, EventArgs e)
{
if (this.counter <= this.second)
{
this.Refresh();
this.counter++;
Debug.WriteLine("-------timer start----");
}
else
{
this.timer1.Enabled = false;
pictureBox_OFF.Visible = false;
this.timer1.Stop();
// this.Close();
Debug.WriteLine("-------timer Close----");
}
}
protected override void WndProc(ref Message msg)
{
base.WndProc(ref msg);
switch (msg.Msg)
{
case WM_HOTKEY: //窗口消息:热键
int tmpWParam = msg.WParam.ToInt32();
if (tmpWParam == HotKeyVOLUME_UPID)
{
//加音量
//SendMessage(this.Handle, WM_APPCOMMAND, 0x30292, APPCOMMAND_VOLUME_UP * 0x10000);
pictureBox_OFF.Image = turnOFF;
this.counter = 0;
this.timer1.Enabled = true;
this.timer1.Interval = 1000;
this.timer1.Start();
Debug.WriteLine("按了F6");
}
if (tmpWParam == HotKeyVOLUME_DOWN)
{
//减音量
//SendMessage(this.Handle, WM_APPCOMMAND, 0x30292, APPCOMMAND_VOLUME_DOWN * 0x10000);
Debug.WriteLine("按了F7");
pictureBox_OFF.Image = turnON;
this.counter = 0;
this.timer1.Enabled = true;
this.timer1.Interval = 1000;
this.timer1.Start();
}
if (tmpWParam == HotKeyVOLUME_MUTE)
{
//静音
Debug.WriteLine("按了F5");
SendMessage(this.Handle, WM_APPCOMMAND, 0x200eb0, APPCOMMAND_VOLUME_MUTE * 0x10000);
Debug.WriteLine("静量");
}
break;
case WM_CREATE: //窗口消息:创建
SystemHotKey.RegHotKey(this.Handle, HotKeyVOLUME_UPID, SystemHotKey.KeyModifiers.None, Keys.F6);
SystemHotKey.RegHotKey(this.Handle, HotKeyVOLUME_DOWN, SystemHotKey.KeyModifiers.None, Keys.F7);
SystemHotKey.RegHotKey(this.Handle, HotKeyVOLUME_MUTE, SystemHotKey.KeyModifiers.None, Keys.F5);
break;
case WM_DESTROY: //窗口消息:销毁
SystemHotKey.UnRegHotKey(this.Handle, HotKeyVOLUME_UPID); //销毁热键
SystemHotKey.UnRegHotKey(this.Handle, HotKeyVOLUME_DOWN); //销毁热键
SystemHotKey.UnRegHotKey(this.Handle, HotKeyVOLUME_MUTE); //销毁热键
break;
default:
break;
}
}
}
}
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace HotkeyTest
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private int second=3;
private int counter;
Image turnOFF = Resource1.OFF;
Image turnON = Resource1.ON;
private const int WM_HOTKEY = 0x312; //窗口消息:热键
private const int WM_CREATE = 0x1; //窗口消息:创建
private const int WM_DESTROY = 0x2; //窗口消息:销毁
private const int HotKeyVOLUME_UPID = 1; //热键ID(自定义)
private const int HotKeyVOLUME_DOWN = 2; //热键ID(自定义)
private const int HotKeyVOLUME_MUTE = 3; //热键ID(自定义)
//音量
[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
static extern IntPtr SendMessage(IntPtr hWnd, uint Msg, uint wParam, uint lParam);
const uint WM_APPCOMMAND = 0x319;
const uint APPCOMMAND_VOLUME_UP = 0x0a;
const uint APPCOMMAND_VOLUME_DOWN = 0x09;
const uint APPCOMMAND_VOLUME_MUTE = 0x08;
//picturebox show time
private void timer1_Tick(object sender, EventArgs e)
{
if (this.counter <= this.second)
{
this.Refresh();
this.counter++;
Debug.WriteLine("-------timer start----");
}
else
{
this.timer1.Enabled = false;
pictureBox_OFF.Visible = false;
this.timer1.Stop();
// this.Close();
Debug.WriteLine("-------timer Close----");
}
}
protected override void WndProc(ref Message msg)
{
base.WndProc(ref msg);
switch (msg.Msg)
{
case WM_HOTKEY: //窗口消息:热键
int tmpWParam = msg.WParam.ToInt32();
if (tmpWParam == HotKeyVOLUME_UPID)
{
//加音量
//SendMessage(this.Handle, WM_APPCOMMAND, 0x30292, APPCOMMAND_VOLUME_UP * 0x10000);
pictureBox_OFF.Image = turnOFF;
this.counter = 0;
this.timer1.Enabled = true;
this.timer1.Interval = 1000;
this.timer1.Start();
Debug.WriteLine("按了F6");
}
if (tmpWParam == HotKeyVOLUME_DOWN)
{
//减音量
//SendMessage(this.Handle, WM_APPCOMMAND, 0x30292, APPCOMMAND_VOLUME_DOWN * 0x10000);
Debug.WriteLine("按了F7");
pictureBox_OFF.Image = turnON;
this.counter = 0;
this.timer1.Enabled = true;
this.timer1.Interval = 1000;
this.timer1.Start();
}
if (tmpWParam == HotKeyVOLUME_MUTE)
{
//静音
Debug.WriteLine("按了F5");
SendMessage(this.Handle, WM_APPCOMMAND, 0x200eb0, APPCOMMAND_VOLUME_MUTE * 0x10000);
Debug.WriteLine("静量");
}
break;
case WM_CREATE: //窗口消息:创建
SystemHotKey.RegHotKey(this.Handle, HotKeyVOLUME_UPID, SystemHotKey.KeyModifiers.None, Keys.F6);
SystemHotKey.RegHotKey(this.Handle, HotKeyVOLUME_DOWN, SystemHotKey.KeyModifiers.None, Keys.F7);
SystemHotKey.RegHotKey(this.Handle, HotKeyVOLUME_MUTE, SystemHotKey.KeyModifiers.None, Keys.F5);
break;
case WM_DESTROY: //窗口消息:销毁
SystemHotKey.UnRegHotKey(this.Handle, HotKeyVOLUME_UPID); //销毁热键
SystemHotKey.UnRegHotKey(this.Handle, HotKeyVOLUME_DOWN); //销毁热键
SystemHotKey.UnRegHotKey(this.Handle, HotKeyVOLUME_MUTE); //销毁热键
break;
default:
break;
}
}
}
}
0 0
- Windows Hotkey control volume
- windows hotkey
- windows hotkey overall
- UVALive 6843 Volume Control
- hotkey
- HotKey
- hotkey
- HotKey
- No Volume Control GStreamer plugin
- debian6不能使用gnome-volume-control
- Six Sigma and Beyond: Statistical Process Control, Volume IV
- Cisco Network Admission Control, Volume II: NAC Deployment and Troubleshooting
- How to use softvol to control the master volume
- UVALive 6843Volume Control(暴力压位)
- How to use softvol to control the master volume
- UVALive 6843 Volume Control(暴力压位)
- volume
- volume
- 排序7:希尔排序
- POJ2142The Balance扩展欧几里得
- bzoj1416&1498: [NOI2006]神奇的口袋
- 数据库列 操作
- Leetcode Algorithm 062. Unique Paths
- Windows Hotkey control volume
- Java 链表的底层实现
- JavaScript学习笔记28-数组
- 排序8:排序算法的分析
- 高德地图——加载当前位置 LBS获取自定义坐标
- Android AutoLayout全优屏幕适配方式
- 踩完百度首页坑,亲测可用android录像,mediaRecord
- Java ArrayList的底层实现
- postman测试工具