方法1:

[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_MUTE = 0x08;

然后调用:

SendMessage(new WindowInteropHelper(this).Handle, WM_APPCOMMAND, 0x200eb0, APPCOMMAND_VOLUME_MUTE * 0x10000);

方法2:

模拟按键的方式。

定义KeyController类:

public class KeyController
{
#region bVk参数 常量定义 public const byte vbKeyLButton = 0x1; // 鼠标左键
public const byte vbKeyRButton = 0x2; // 鼠标右键
public const byte vbKeyCancel = 0x3; // CANCEL 键
public const byte vbKeyMButton = 0x4; // 鼠标中键
public const byte vbKeyBack = 0x8; // BACKSPACE 键
public const byte vbKeyTab = 0x9; // TAB 键
public const byte vbKeyClear = 0xC; // CLEAR 键
public const byte vbKeyReturn = 0xD; // ENTER 键
public const byte vbKeyShift = 0x10; // SHIFT 键
public const byte vbKeyControl = 0x11; // CTRL 键
public const byte vbKeyAlt = ; // Alt 键 (键码18)
public const byte vbKeyMenu = 0x12; // MENU 键
public const byte vbKeyPause = 0x13; // PAUSE 键
public const byte vbKeyCapital = 0x14; // CAPS LOCK 键
public const byte vbKeyEscape = 0x1B; // ESC 键
public const byte vbKeySpace = 0x20; // SPACEBAR 键
public const byte vbKeyPageUp = 0x21; // PAGE UP 键
public const byte vbKeyEnd = 0x23; // End 键
public const byte vbKeyHome = 0x24; // HOME 键
public const byte vbKeyLeft = 0x25; // LEFT ARROW 键
public const byte vbKeyUp = 0x26; // UP ARROW 键
public const byte vbKeyRight = 0x27; // RIGHT ARROW 键
public const byte vbKeyDown = 0x28; // DOWN ARROW 键
public const byte vbKeySelect = 0x29; // Select 键
public const byte vbKeyPrint = 0x2A; // PRINT SCREEN 键
public const byte vbKeyExecute = 0x2B; // EXECUTE 键
public const byte vbKeySnapshot = 0x2C; // SNAPSHOT 键
public const byte vbKeyDelete = 0x2E; // Delete 键
public const byte vbKeyHelp = 0x2F; // HELP 键
public const byte vbKeyNumlock = 0x90; // NUM LOCK 键 //常用键 字母键A到Z
public const byte vbKeyA = ;
public const byte vbKeyB = ;
public const byte vbKeyC = ;
public const byte vbKeyD = ;
public const byte vbKeyE = ;
public const byte vbKeyF = ;
public const byte vbKeyG = ;
public const byte vbKeyH = ;
public const byte vbKeyI = ;
public const byte vbKeyJ = ;
public const byte vbKeyK = ;
public const byte vbKeyL = ;
public const byte vbKeyM = ;
public const byte vbKeyN = ;
public const byte vbKeyO = ;
public const byte vbKeyP = ;
public const byte vbKeyQ = ;
public const byte vbKeyR = ;
public const byte vbKeyS = ;
public const byte vbKeyT = ;
public const byte vbKeyU = ;
public const byte vbKeyV = ;
public const byte vbKeyW = ;
public const byte vbKeyX = ;
public const byte vbKeyY = ;
public const byte vbKeyZ = ; //数字键盘0到9
public const byte vbKey0 = ; // 0 键
public const byte vbKey1 = ; // 1 键
public const byte vbKey2 = ; // 2 键
public const byte vbKey3 = ; // 3 键
public const byte vbKey4 = ; // 4 键
public const byte vbKey5 = ; // 5 键
public const byte vbKey6 = ; // 6 键
public const byte vbKey7 = ; // 7 键
public const byte vbKey8 = ; // 8 键
public const byte vbKey9 = ; // 9 键 public const byte vbKeyNumpad0 = 0x60; //0 键
public const byte vbKeyNumpad1 = 0x61; //1 键
public const byte vbKeyNumpad2 = 0x62; //2 键
public const byte vbKeyNumpad3 = 0x63; //3 键
public const byte vbKeyNumpad4 = 0x64; //4 键
public const byte vbKeyNumpad5 = 0x65; //5 键
public const byte vbKeyNumpad6 = 0x66; //6 键
public const byte vbKeyNumpad7 = 0x67; //7 键
public const byte vbKeyNumpad8 = 0x68; //8 键
public const byte vbKeyNumpad9 = 0x69; //9 键
public const byte vbKeyMultiply = 0x6A; // MULTIPLICATIONSIGN(*)键
public const byte vbKeyAdd = 0x6B; // PLUS SIGN(+) 键
public const byte vbKeySeparator = 0x6C; // ENTER 键
public const byte vbKeySubtract = 0x6D; // MINUS SIGN(-) 键
public const byte vbKeyDecimal = 0x6E; // DECIMAL POINT(.) 键
public const byte vbKeyDivide = 0x6F; // DIVISION SIGN(/) 键 //F1到F12按键
public const byte vbKeyF1 = 0x70; //F1 键
public const byte vbKeyF2 = 0x71; //F2 键
public const byte vbKeyF3 = 0x72; //F3 键
public const byte vbKeyF4 = 0x73; //F4 键
public const byte vbKeyF5 = 0x74; //F5 键
public const byte vbKeyF6 = 0x75; //F6 键
public const byte vbKeyF7 = 0x76; //F7 键
public const byte vbKeyF8 = 0x77; //F8 键
public const byte vbKeyF9 = 0x78; //F9 键
public const byte vbKeyF10 = 0x79; //F10 键
public const byte vbKeyF11 = 0x7A; //F11 键
public const byte vbKeyF12 = 0x7B; //F12 键 #endregion #region 引用win32api方法 /// <summary>
/// 导入模拟键盘的方法
/// </summary>
/// <param name="bVk" >按键的虚拟键值</param>
/// <param name= "bScan" >扫描码,一般不用设置,用0代替就行</param>
/// <param name= "dwFlags" >选项标志:0:表示按下,2:表示松开</param>
/// <param name= "dwExtraInfo">一般设置为0</param>
[DllImport("user32.dll")]
public static extern void keybd_event(byte bVk, byte bScan, int dwFlags, int dwExtraInfo); #endregion
}

然后模拟按钮:

KeyController.keybd_event(, , , );
Thread.Sleep();
KeyController.keybd_event(, , , );

WPF实现系统禁音的方法的更多相关文章

  1. WPF 获取系统 DPI 的多种方法

    原文:WPF 获取系统 DPI 的多种方法 WPF 获取系统 DPI 的多种方法 由于 WPF 的尺寸单位和系统的 DPI 相关,我们有时需要获取 DPI 值来进行一些界面布局的调整,本文汇总了一些 ...

  2. WPF - 属性系统 (4 of 4)

    依赖项属性的重写 在基于C#的编程中,对属性的重写常常是一种行之有效的解决方案:在基类所提供的属性访问符实现不能满足当前要求的时候,我们就需要重新定义属性的访问符. 但对于依赖项属性而言,属性执行逻辑 ...

  3. WPF - 属性系统 (3 of 4)

    依赖项属性元数据 在前面的章节中,我们已经介绍了WPF依赖项属性元数据中的两个组成:CoerceValueCallback回调以及PropertyChangedCallback.而在本节中,我们将对其 ...

  4. WPF - 属性系统 (1 of 4)

    本来我希望这一系列文章能够深入讲解WPF属性系统的实现以及XAML编译器是如何使用这些依赖项属性的,并在最后分析WPF属性系统的实际实现代码.但是在编写的过程中发现对WPF属性系统代码的讲解要求之前的 ...

  5. WPF布局系统[转]

    转自:http://www.cnblogs.com/niyw/archive/2010/10/31/1863908.html前言 前段时间忙了一阵子Google Earth,这周又忙了一阵子架构师论文 ...

  6. WPF显示html的几种方法

    原文:WPF显示html的几种方法 客户希望系统在一些特定的条件下,界面上能显示用户自定义的格式和内容,格式和内容通过html指定. 基本上在wpf中显示html有以下四种方法. 1.       W ...

  7. 【系统之音】WindowManager工作机制详解

    前言 目光所及,皆有Window!Window,顾名思义,窗口,它是应用与用户交互的一个窗口,我们所见到视图,都对应着一个Window.比如屏幕上方的状态栏.下方的导航栏.按音量键调出来音量控制栏.充 ...

  8. 【系统之音】Android进程的创建及启动简述

    Android系统中的进程(这里不包括init等底层的进程)都是通过Zygote fork而来的,那这些进程的启动流程都是怎样的呢? 这里将Android进程分为两个部分: (1)系统框架进程Syst ...

  9. WPF - 属性系统 (2 of 4)

    属性更改回调 前一章的示例中,对各个参数的设置都非常容易理解.如果我们仅仅需要创建一个独立的依赖项属性,那么上面所提到的创建依赖项属性的基础知识足以满足需求.但是事情往往并非如此完美.在一个系统中,很 ...

随机推荐

  1. [CortexM0--stm32f0308]Option Byte

    问题描写叙述 option byte,算是IC中比較简单的功能,就是用户能够写入数据,对IC的某些功能进行配置.而IC在reset时,会载入当中的内容,进行推断,从而使用户的配置生效. option ...

  2. as.data.frame一定要小心的一个參数stringsAsFactors

    假设说一个data.frame中的元素是factor.你想转化成numeric,你会怎么做?比方d[1,1]是factor   正确答案是 先as.character(x) 再as.numeric(x ...

  3. echarts多条折线图和柱状图实现

    参考链接:echarts官网:http://echarts.baidu.com/原型图(效果图): 图片.png 代码: <!DOCTYPE html> <html> < ...

  4. 高并发測试工具webbench

    1.简单介绍 webbench最多能够模拟3万个并发连接去測试server的负载能力.编译和配置简单,仅基于TCP协议上对server进行測试. Webbench也是开放源代码.从代码上看,每一个cl ...

  5. java命名规则(转)

    1. JAVA源文件的命名 JAVA源文件名必须和源文件中所定义的类的类名相同. 2. Package的命名 Package名的第一部分应是小写ASCII字符,并且是顶级域名之一,通常是com.edu ...

  6. 更改MyEclipse编辑框的背景颜色

    更改MyEclipse编辑框的背景颜色 1.未改动之前.编辑框背景色 2.依次操作,"Window--->Preferences" 3.选择"General---& ...

  7. 【bzoj2453】维护队列 (分块 + 二分)

    传送门(权限题) 题目分析 题意为:求区间内有多少种不同的数,带修改. 首先对原序列分块,用last[i]表示与i相同的上一个在哪里,然后将分块后的数组每个块内的按照last进行排序,这样查询时就可以 ...

  8. 在Windows中安装MinGW-w64(有图,一步一步)

    在Windows中安装MinGW-w64 发表回复 如需配合Sublime Text 3编译C程序, 请参考本站文章: 使用Sublime Text 3与MinGW-w64编译C语言程序 MinGW, ...

  9. 不安装 oracle的客户,就可以使用pl/sql访问远程oracle 数据库的方法

    免安装Oracle客户端使用PL/SQL连接Oracle      大家都知道,用PL/SQL连接Oracle,是需要安装Oracle客户端软件的.有没要想过不安装Oracle客户端直接连接Oracl ...

  10. SQL2008错误:当 MUST_CHANGE 为 ON (开)时,不能将 CHECK_POLICY 和 CHECK_EXPIRATION 选项设为 OFF (关)。

    假设出现这样的情况,第一个选择是: 在数据库用户管理中去掉了"强制password过期"! 假设把"强制实施password策略"的勾也去掉了,出现例如以下错误 ...