方法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. MySQL 基础查询

    6月业绩榜 名次   伙伴 业绩 签单 面谈 每日目标 1 杜艳花 12367 2 0 查看目标 2 郑东杰 2345 1 0 查看目标 3 黄传龙 345 1 1 查看目标 4 測试 0 0 0 查 ...

  2. 【hdu 3863】No Gambling

    Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65568/32768 K (Java/Others) Total Submission(s) ...

  3. Oracle 自己主动内存參数依赖性

    图例:在该图中使用了下面參数名称缩写: MT = MEMORY_TARGET MMT = MEMORY_MAX_TARGET ST = SGA_TARGET PAT = PGA_AGGREGATE_T ...

  4. PHP/HTML混写的四种方式总结

    PHP/HTML混写的四种方式总结 一.总结 一句话总结: 注意点: 1.双引号里面解析变量:echo "$Content" 2.HEREDOC和NOWDOC的关系:类似于双引号包 ...

  5. python request 代理/超时/证书

    import requests headers = { "User-Agent": "Mozilla/5.0 (Windows NT 6.1; Win64; x64) A ...

  6. 【record】11.7..11.13

    好少

  7. WPF 等距布局

    原文:WPF 等距布局 本文告诉大家如何使用 WPF 的自定义布局做等距布局. 实际做的效果很简单,因为在开发我容易就用到了等距的控件.等距控件就是在指定的宽度下,平均把控件放在水平的地方,这样相等于 ...

  8. IT企业级应?开发模式演化

    原文:IT企业级应?开发模式演化 前端研发流程 传统To B类系统的研发模式 探索 & 思考设计模式库(DPL)设计语⾔设计语⾔详解基于MVVM模式的Web框架 & UI库优化后的开发 ...

  9. sgu209:Areas(计算几何)

    意甲冠军: 给一些直.这架飞机被分成了很多这些线性块.每个块的需求面积封闭曲线图. 分析: ①我们应要求交点22的直线: ②每行上的交点的重排序,借此来离散一整行(正反两条边): ③对于连向一个点的几 ...

  10. Android二维码功能实现

    最近二维码真是越来越火了,随便电视上.网络上.商场里,到处都是二维码.而内嵌二维码扫描功能的软件也越来越多,QQ.微信.UC浏览器等等应用都可以对着二维码扫一扫,感觉我们自己的应用里不加上二维码扫描功 ...