Is there any way to determine the CAPS LOCK state in VB. NET, without
calling any VB6-style Windows API?

Re: Determine CAPS LOCK state in VB. NET by Herfried

Herfried
Fri Dec 31 07:37:32 CST 2004

"Magnus Österberg" <magnus.osterberg@abo.fi> schrieb:
> Is there any way to determine the CAPS LOCK state in VB. NET, without
> calling any VB6-style Windows API?

AFAIK, no.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>



Re: Determine CAPS LOCK state in VB. NET by Tom

Tom
Fri Dec 31 11:06:59 CST 2004

Here's the code, from a .Net version of Notepad I wrote once. It's in C#,
unfortunately, but converting it to VB.Net shouldn't be too tough. Looks
like it lost its formatting when I pasted it from VS.Net...

Tom Dacon
Dacon Software Consulting

/// <summary>

/// Windows API function to get the key state of various keyboard keys,

/// such as the Caps Lock key and so forth.

/// </summary>

/// <param name="keyCode"></param>

/// <returns></returns>

[DllImport("user32.dll", CharSet=CharSet.Auto, ExactSpelling=true,
CallingConvention=CallingConvention.Winapi)]

private static extern short GetKeyState(int keyCode);


// Selections from platform SDK WinUser.h

private const int VK_CAPITAL = 0x14;

private const int VK_INSERT = 0x2D;

private const int VK_NUMLOCK = 0x90;

private const int VK_SCROLL = 0x91;

/// <summary>

/// When the user interface goes idle, update the keyboard state

/// annunciators on the status bar.

/// </summary>

/// <param name="sender"></param>

/// <param name="e"></param>

/// <remarks>This event handler is wired to Application.Idle</remarks>

public void OnIdle(object sender, EventArgs e)

{

// Update the panels when the program is idle.

bool capsLock = (((ushort) GetKeyState(VK_CAPITAL)) & 0xffff) != 0;

bool insKey = (((ushort) GetKeyState(VK_INSERT)) & 0xffff) != 0;

bool numLock = (((ushort) GetKeyState(VK_NUMLOCK)) & 0xffff) != 0;

bool scrLock = (((ushort) GetKeyState(VK_SCROLL)) & 0xffff) != 0;

this.statusBar1.Panels[SbpCapsIndex].Text = ( capsLock ? "CAP" : "");

this.statusBar1.Panels[SbpInsIndex].Text = ( insKey ? "INS" : "OVR");

}

"Magnus Österberg" <magnus.osterberg@abo.fi> wrote in message
news:#lIQWYz7EHA.1596@tk2msftngp13.phx.gbl...
> Is there any way to determine the CAPS LOCK state in VB. NET, without
> calling any VB6-style Windows API?
>
>



Re: Determine CAPS LOCK state in VB. NET by Herfried

Herfried
Fri Dec 31 13:13:47 CST 2004

"Tom Dacon" <tdacon@community.nospam> schrieb:
> like it lost its formatting when I pasted it from VS.Net...

You can avoid that by pasting the code into notepad first, then selecting
and copying it again and pasting it into your newsreader.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>



Re: Determine CAPS LOCK state in VB. NET by Tom

Tom
Sat Jan 01 12:31:03 CST 2005

Thanks, Herfried.

TD

"Herfried K. Wagner [MVP]" <hirf-spam-me-here@gmx.at> wrote in message
news:eG5Gcz27EHA.2568@TK2MSFTNGP10.phx.gbl...
> "Tom Dacon" <tdacon@community.nospam> schrieb:
>> like it lost its formatting when I pasted it from VS.Net...
>
> You can avoid that by pasting the code into notepad first, then selecting
> and copying it again and pasting it into your newsreader.
>
> --
> M S Herfried K. Wagner
> M V P <URL:http://dotnet.mvps.org/>
> V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
>