473,657 Members | 2,407 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 21977
Hello Gidi,

Use
SendKeys.Send(" {CAPSLOCK}");

or

PInvoke "SetKeyboardSta te"/"keybd_even t"

[DllImport("user 32.dll")]
static extern bool SetKeyboardStat e(byte [] lpKeyState);

[DllImport("user 32.dll")]
static extern void keybd_event(byt e 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 "SetKeyboardSta te"/"keybd_even t"

[DllImport("user 32.dll")]
static extern bool SetKeyboardStat e(byte [] lpKeyState);

[DllImport("user 32.dll")]
static extern void keybd_event(byt e 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("user 32.dll")]
static extern void keybd_event(byt e bVk, byte bScan, uint dwFlags,
UIntPtr dwExtraInfo);
...
}

4) add code below to the button handler

private void button1_Click(o bject sender, EventArgs e)
{
const int KEYEVENTF_EXTEN DEDKEY = 0x1;
const int KEYEVENTF_KEYUP = 0x2;
keybd_event(0x1 4, 0x45, KEYEVENTF_EXTEN DEDKEY, (UIntPtr) 0);
keybd_event(0x1 4, 0x45, KEYEVENTF_EXTEN DEDKEY | 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 "SetKeyboardSta te"/"keybd_even t"

[DllImport("user 32.dll")]
static extern bool SetKeyboardStat e(byte [] lpKeyState);
[DllImport("user 32.dll")]

static extern void keybd_event(byt e bVk, byte bScan, uint dwFlags,
UIntPtr

dwExtraInfo);

http://msdn.microsoft.com/library/de...ary/en-us/winu
i/WinUI/WindowsUserInte rface/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("user 32.dll")]
static extern void keybd_event(byt e bVk, byte bScan, uint dwFlags,
UIntPtr dwExtraInfo);
...
}

4) add code below to the button handler

private void button1_Click(o bject sender, EventArgs e)
{
const int KEYEVENTF_EXTEN DEDKEY = 0x1;
const int KEYEVENTF_KEYUP = 0x2;
keybd_event(0x1 4, 0x45, KEYEVENTF_EXTEN DEDKEY, (UIntPtr) 0);
keybd_event(0x1 4, 0x45, KEYEVENTF_EXTEN DEDKEY | 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 "SetKeyboardSta te"/"keybd_even t"

[DllImport("user 32.dll")]
static extern bool SetKeyboardStat e(byte [] lpKeyState);
[DllImport("user 32.dll")]

static extern void keybd_event(byt e bVk, byte bScan, uint dwFlags,
UIntPtr

dwExtraInfo);

http://msdn.microsoft.com/library/de...ary/en-us/winu
i/WinUI/WindowsUserInte rface/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
3316
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 (and whatever it contains), associated with class, 'a'. Somewhere else in, 'topdiv', there is a span or element (containing whatever), associated with class, 'b'.
30
7421
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 cataloged on that node...this works from v7.2 Fixpack 11 clients and servers, but with v8.1 server I get SQL1334N. Does anyone has an idea? Thanks
4
2477
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
2954
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 cookieless sessions for a particular user, and if so, I'd instruct ASP.NET to turn on cookieless sessions for a particular user session. Is this possible? For example I want to use cookie based sessions by default for all users. But if a user has...
2
2190
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 HttpRequestValidationException that gets thrown if HTML is included in the Form, doesn't get thrown. This is fine. However, on some of those pages, there are fields where I don't want
4
1883
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> As desired it plays in a loop as soon as the web page is opened but i want a button ont there that can turn it off. Is there a javascript option to turn of the playing mp3?
10
2434
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 "extend the license", so it will last another week. It consists of queries, forms, and tables, format Access 2003. Bart
4
11407
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 GetWebRequest(System.Uri uri) which returns a WebRequest instance. Though MSDN doesn't make clear statement. I experiment and prove that SoapHttpClientProtocol use this method to create HttpWebRequest for HTTP request. So, I override this...
0
8411
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8323
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8838
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8739
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
7351
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6176
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4173
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2740
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 we have to send another system
2
1969
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.