通过.Net编码在键盘上执行Caps Lock键 [英] To execute Caps Lock on into keyboard by .Net coding

查看:117
本文介绍了通过.Net编码在键盘上执行Caps Lock键的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我下面的代码可以很好地运行以自动将Num Locks设置到键盘上.
但是,如果将Caps Lock锁定在键盘上,如何执行自动设置????

My below code is fine run to auto set the Num Locks on into keyboard.
But how execute to auto set in case of Caps Lock on into keyboard????

public struct INPUT
{
internal int type;
internal short wVk;
internal short wScan;
internal int dwFlags;
internal int time;
internal IntPtr dwExtraInfo;
internal int type1;
internal short wVk1;
internal short wScan1;
internal int dwFlags1;
internal int time1;
internal IntPtr dwExtraInfo1;
}
[DllImport("user32.dll")]
static extern int SendInput(uint nInputs, IntPtr pInputs, int cbSize);

public void SetNumlockOn()
{
const int mouseInpSize = 28;
INPUT input = new INPUT();
input.type = 0x01; //INPUT_KEYBOARD
input.wVk = 0x90; //VK_NUMLOCK
input.wScan = 0;
input.dwFlags = 0; //key-down
input.time = 0;
input.dwExtraInfo = IntPtr.Zero;

input.type1 = 0x01;
input.wVk1 = 0x90;
input.wScan1 = 0;
input.dwFlags1 = 2; //key-up
input.time1 = 0;
input.dwExtraInfo1 = IntPtr.Zero;

IntPtr pI = Marshal.AllocHGlobal(mouseInpSize * 2);
Marshal.StructureToPtr(input, pI, false);
int result = SendInput(2, pI, mouseInpSize);
Marshal.FreeHGlobal(pI);
}



请帮助我....



Please help me....

推荐答案

这是一个论坛,提供您需要打开大写锁定的答案:

http://bytes.com/topic/c-sharp/answers/464602- may-turn-off-caps_lock [ ^ ]

不过,我会质疑其背后的目的.通常最好将键盘留给用户使用.如果您打开Caps Lock,则用户可能会退出您的应用程序以进行其他操作,并对Caps Lock处于打开状态感到沮丧.然后,当他们切换回您的应用程序并将其重新打开时,他们会感到更加沮丧.我建议您在走这条路之前,请认真考虑自己的要求.
Here is a forum with the answer you need on turning the Caps Lock on:

http://bytes.com/topic/c-sharp/answers/464602-possible-turn-off-caps_lock[^]

I would question the purpose behind this, though. It is usually best to leave the keyboard to the user. If you turn on the Caps Lock, the user might switch out of your application to work on something else and get frustrated that Caps Lock is on. Then when they switch back to your app and you turn it back on, they will get even more frustrated. I would recommend you think long and hard about your requirements before you go down this road.


The code in this article[^] should get you going.

I agree with Tim however, not a good idea to force the CAPS Lock on.

If you want to force all data in your application to be in uppercase then convert the strings when capturing/validating etc to uppercase regardless of the state of the key.


这篇关于通过.Net编码在键盘上执行Caps Lock键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆