Hello Gidi,
For second options
1) add using System.Runtime.InteropServices;
2) Put button on the form
3) add code below to the class declaraion where is button handler located
public partial class Form1 : Form
{
[DllImport("user32.dll")]
static extern void keybd_event(byte bVk, byte bScan, uint dwFlags,
UIntPtr dwExtraInfo);
...
}
4) add code below to the button handler
private void button1_Click(object sender, EventArgs e)
{
const int KEYEVENTF_EXTENDEDKEY = 0x1;
const int KEYEVENTF_KEYUP = 0x2;
keybd_event(0x14, 0x45, KEYEVENTF_EXTENDEDKEY, (UIntPtr) 0);
keybd_event(0x14, 0x45, KEYEVENTF_EXTENDEDKEY | KEYEVENTF_KEYUP,
(UIntPtr) 0);
}
This will turn on/off caps lock each time u press the button
0x14 is a Virtual-key code for capslock. List of codes are here
http://msdn.microsoft.com/library/d...wsUserInterface/UserInput/VirtualKeyCodes.asp
G> Thanks Michael ,
G>
G> I tried the SendKeys option, and it works only while i'm debugging,
G> but in regular runtime it doesn't turn on\off the capslock key.
G>
G> About the second option, i didn't really understand how should i use
G> it, so if u can, please explain or give example...
G>
G> Thanks,
G> Gidi.
G> "Michael Nemtsev" wrote:
G>
Hello Gidi,
Use SendKeys.Send("{CAPSLOCK}");
or
PInvoke "SetKeyboardState"/"keybd_event"
[DllImport("user32.dll")]
static extern bool SetKeyboardState(byte [] lpKeyState);
[DllImport("user32.dll")]
static extern void keybd_event(byte bVk, byte bScan, uint dwFlags,
UIntPtr
dwExtraInfo);
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winu
i/WinUI/WindowsUserInterface/UserInput/VirtualKeyCodes.asp
G> Hi,
G>
G> Is it possible to turn on\off the CAPS LOCK button using C#
program?
G> and if so, how can i do that?
G>
G> Thanks,
G> Gidi
---
WBR,
Michael Nemtsev :: blog:
http://spaces.msn.com/laflour
"At times one remains faithful to a cause only because its opponents
do not cease to be insipid." (c) Friedrich Nietzsche
---
WBR,
Michael Nemtsev :: blog:
http://spaces.msn.com/laflour
"At times one remains faithful to a cause only because its opponents do not
cease to be insipid." (c) Friedrich Nietzsche