C#控制键盘按键(大小写按键等)的代码
将代码过程较好的代码段做个记录,如下的资料是关于C#控制键盘按键(大小写按键等)的代码。
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;
namespace sn设置键盘大小写
{
public partial class Form1 : Form
{
const uint KEYEVENTF_EXTENDEDKEY = 0x1;
const uint KEYEVENTF_KEYUP = 0x2;
[DllImport("user32.dll")]
static extern short GetKeyState(int nVirtKey);
[DllImport("user32.dll")]
static extern void keybd_event(byte bVk, byte bScan, uint dwFlags, uint dwExtraInfo);
public enum VirtualKeys : byte
{
VK_A = 62
}
public Form1()
{
InitializeComponent();
}
public static bool GetState(VirtualKeys Key)
{
return (GetKeyState((int)Key)==1);
}
public static void SetState(VirtualKeys Key, bool State)
{
if (State != GetState(Key))
{
keybd_event((byte)Key, 0x45, KEYEVENTF_EXTENDEDKEY | 0, 0);
keybd_event((byte)Key, 0x45, KEYEVENTF_EXTENDEDKEY | KEYEVENTF_KEYUP, 0);
}
}
private void btnOpenCAPITAL_Click(object sender, EventArgs e)
{
SetState(VirtualKeys.VK_CAPITAL, true);
}
private void btnCloseCAPITAL_Click(object sender, EventArgs e)
{
SetState(VirtualKeys.VK_CAPITAL, false);
}
private void btnOpenScroll_Click(object sender, EventArgs e)
{
SetState(VirtualKeys.VK_SCROLL, true);
}
private void btnCloseScroll_Click(object sender, EventArgs e)
{
SetState(VirtualKeys.VK_SCROLL, false);
}
private void btnOpenNum_Click(object sender, EventArgs e)
{
SetState(VirtualKeys.VK_NUMLOCK, true);
}
private void btnCloseNum_Click(object sender, EventArgs e)
{
SetState(VirtualKeys.VK_NUMLOCK, false);
}
}
}
C#控制键盘按键(大小写按键等)的代码的更多相关文章
- MCU 51-4 独立按键&编码按键
独立按键: 按键的按下与释放是通过机械触点的闭合与断开来实现的,因机械触点的弹性作用,在闭合与断开的瞬间均有一个抖动的过程,抖动必须清除. 按键按下一次,数码管数值加1: #include<re ...
- 入门级的按键驱动——按键驱动笔记之poll机制-异步通知-同步互斥阻塞-定时器防抖
文章对应视频的第12课,第5.6.7.8节. 在这之前还有查询方式的驱动编写,中断方式的驱动编写,这篇文章中暂时没有这些类容.但这篇文章是以这些为基础写的,前面的内容有空补上. 按键驱动——按下按键, ...
- AD按键-矩阵按键:
原理:利用数组分压+AD采集: 优点:一个IO口可以做成多个按键,节省IO口(矩阵键盘在>4时优点才能体现出来):可备用作为AD基准输入. 缺点:不能做成组合按键(或者电阻要精确选择):且离IO ...
- Python3 tkinter基础 event keysym 查看按键的按键名
Python : 3.7.0 OS : Ubuntu 18.04.1 LTS IDE : PyCharm 2018.2.4 Conda ...
- AD按键-矩阵按键-独立按键:
原理:利用数组分压+AD采集: 优点:一个IO口可以做成多个按键,节省IO口(矩阵键盘在>4时优点才能体现出来):可备用作为AD基准输入. 缺点:不能做成组合按键(或者电阻要精确选择):且离IO ...
- 监听Ueditor的 iframe中的按键,按键组合事件(Ctrl+s)
个人博客 地址:https://www.wenhaofan.com/a/20190716214214 监听按键事件 ueditor.ready(function() { UE.dom.domU ...
- 按键显示按键编码 keycode
<!doctype html> <html> <head> <meta charset="utf-8"> <title> ...
- Qt之键盘事件监听-实时响应大小写Capslock按键
目录 一.开篇 二.效果展示 三.实现思路 1.重写QLlinEdit 2.全局应用程序事件 3.windows钩子 四.相关文章 原文链接:Qt之键盘事件监听-实时响应大小写Capslock按键 一 ...
- Linux按键驱动程序设计--从简单到不简单【转】
本文转载自:http://blog.csdn.net/coding__madman/article/details/51399353 混杂设备驱动模型: 1. 混杂设备描述 在Linux系统中,存在一 ...
随机推荐
- HackerRank-Python攻城歷程-3.List( Find the Second Largest Number )
if __name__ == '__main__': n = int(input()) arr = map(int, input().split()) print(sorted(list(set(ar ...
- Python三大神器:装饰器,迭代器,生成器
一.装饰器 由于一个函数能实现一种功能,现在想要在不改变其代码的情况下,让这个函数进化一下,即能保持原来的功能,还能有新的"技能",怎么办? 现已经存在一个自定义的函数func1, ...
- 搭建openstack环境时出现的问题
penstack环境搭建程度(安装完keystone) 然后运行 openstack domain create --description "An Example Domain" ...
- CentOS7 DHCP 服务搭建
一.实验环境 1.VMware12.俩台Linux(Ser 和 Client ).DHCP安装包. 二.操作流程 1.安装DHCP 2.配置DHCP的配置文件: /etc/dhcp/dhcpd. ...
- Premiere Pro 中的键盘快捷键
官网地址:https://helpx.adobe.com/cn/premiere-pro/using/default-keyboard-shortcuts-cc.html?mv=product& ...
- Linux(例如CentOS 7)打开TCP 22端口,基于SSH协议
SSH 为 Secure Shell 的缩写,由 IETF 的网络工作小组(Network Working Group)所制定:SSH 为建立在应用层和传输层基础上的安全协议.SSH 是目前较可靠,专 ...
- Python入门(一)数据类型、循环语句
脚本语言类型: 1.编译型语言:写完代码不能执行,需要先编译 eg:c.c++.c# 2.解释性语言:不需要编译 直接执行 eg:python.jav ...
- 《R语言入门与实践》第四章:R 的记号体系
这一章节将如何对 R 对象中的值进行选取,R 的符号规则有两种方式进行查询: 第一种记号体系:索引查询索引语法:deck[ , ](使用中括号)其中[ , ] 为索引,其中含有两个索引参数,用 &qu ...
- Python Django Web开发的5个优秀好习惯
https://blog.csdn.net/weixin_42134789/article/details/82381854
- mysql5.7 timestamp错误:there can be only oneTIMESTAMP column with CURRENT_TIMESTAMP in DEFAULT or ON UPDATE
#1293 - Incorrect table definition; there can be only oneTIMESTAMP column with CURRENT_TIMESTAMP in ...