473,503 Members | 1,849 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Is it possible to turn on\off CAPS_LOCK ?

Hi,

Is it possible to turn on\off the CAPS LOCK button using C# program? and if
so, how can i do that?

Thanks,
Gidi
Mar 5 '06 #1
4 21912
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/de...alKeyCodes.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
Mar 5 '06 #2
Thanks Michael ,

I tried the SendKeys option, and it works only while i'm debugging, but in
regular runtime it doesn't turn on\off the capslock key.

About the second option, i didn't really understand how should i use it, so
if u can, please explain or give example...

Thanks,
Gidi.

"Michael Nemtsev" wrote:
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/de...alKeyCodes.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

Mar 5 '06 #3
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/de...alKeyCodes.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/de...ary/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
Mar 5 '06 #4
Thanks again Michael,

It works. I have one more question, if it's ok by you...

How can i check if the caps lock is on or off before i calling this event
handler?

Thanks,
Gidi.

"Michael Nemtsev" wrote:
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/de...alKeyCodes.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/de...ary/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

Mar 6 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

39
3281
by: Mark Johnson | last post by:
It doesn't seem possible. But would the following also seem a violation of the general notions behind css? You have a DIV, say asociated with class, 'topdiv'. Inside of that you have an anchor...
30
7380
by: aka | last post by:
Hi I have a DB2 v8.1 on AIX and DB2 Connect EE on Solaris wich is connected to OS/390 DB2 subsystems via APPC / SNA. I have cataloged the DB2 Connect instance as tcpip node and then the Host DB...
4
2456
by: murat oguzalp | last post by:
i want to call base and this constructor at the same time. is is possible? i mean: B(int a, int b, int c):base(a):this(b) { // do something with c } at java i used to do that:
2
2941
by: Steve Franks | last post by:
According to the docs you tell ASP.NET to use cookieless sessions by setting a value in the config.web file. However, what if I wanted to determine at run time whether or not I wanted to use...
2
2184
by: Nick Gilbert | last post by:
Hi I have a number of pages where it is valid for the user to enter HTML. On these pages, I have turned off RequestValidation ("ValidateRequest = false" in the page directive) so that the...
4
1875
by: Malkavian | last post by:
hi. I have this in the header section of my web page. <EMBED SRC="g7wap cq.mp3" WIDTH=0 HEIGHT=0 hidden="true" AUTOSTART=true LOOP=TRUE ALIGN="CENTER" id="morsemp3" name="morsemp3"></EMBED> ...
10
2417
by: AA Arens | last post by:
I do have a database with customer info in it. To avoid it will be taken out of our office, is it possible to make it not-readable after a certain period? then every let say seven days, I needs to...
4
11367
by: Morgan Cheng | last post by:
Days ago, I post a question on how to make SoapHttpClientProtocol instance make new TCP connection for each web service request. Now, I found how. SoapHttpClientProtocol has a protected method...
0
7205
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7348
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7006
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7467
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5592
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
3175
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3166
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1519
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
744
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.