方法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. Ubuntu-Docker[1]安装Docker,通过Docker部署net core代码,需要结合[.NET Core 18]发布、ASP.NET Core Docker部署

    1)通过系统自带包安装 通过自带包安装,可能Docker版本较旧 $ sudo apt-get update Reading package lists... Done $ sudo apt-get ...

  2. .net core 下使用StackExchange的Redis库访问超时解决

    原文:.net core 下使用StackExchange的Redis库访问超时解决 目录 问题:并发稍微多的情况下Redis偶尔返回超时 给出了参考网址? 结论 小备注 引用链接 问题:并发稍微多的 ...

  3. Expression Blend 的点滴(4)--创建类似iPhone屏幕锁控件(上)

    原文:Expression Blend 的点滴(4)--创建类似iPhone屏幕锁控件(上) 本篇文章,最终效果图:  当然,不只是一个UI而已,如果只是一张图片,那专业的设计师能做出更出色的效果.在 ...

  4. 【Python 安装】安装第三方库时 PermissionError: [WinError 5] Access is denied

    对于 windows 用户,在开始菜单中输入 cmd,右键以 run as administrator(以管理员身份运行). Python - PIP install trouble shooting ...

  5. Android Studio教程-创建第一个项目Hello World

    前段时间打开Android studio 在build过程中总会出现以下错误 Error:Execution failed for task ':app:preDebugAndroidTestBuil ...

  6. 符号函数(sign function)性质及应用

    sgn(x):=⎧⎩⎨−101if x<0,if x=0,if x>0. 形式及描述较为简单的数学对象,更应当注意的便是其细节问题,对于 sign 函数(符号函数),便是自变量取值为 0 ...

  7. template.js小小说明

    教程 template.js 一款 JavaScript 模板引擎,简单,好用.提供一套模板语法,用户可以写一个模板区块,每次根据传入的数据,生成对应数据产生的HTML片段,渲染不同的效果. 简介 主 ...

  8. vue 使用jquery (全局)

    1 全局配置jquery , 个人习惯 , 离不开jquery了 然后重启项目 就 完事

  9. 度小于所述过程:KanboxEnt.exe

    在防火墙管理.见未知的过程"KanboxEnt.exe" 程序信息: 版权声明:本文博主原创文章.博客,未经同意不得转载.

  10. Python中 如何将一个字符串分成一个个字符

    其实   一个字符串  实质也是 一个列表 就很简单了: a = ' for item in a: print(item) 打印结果: 121512 如果进而要统计字符出现的次数 , 那就很简单了.