Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Windows Forms / WinForm General / January 2005

Tip: Looking for answers? Try searching our database.

Determine CAPS LOCK state in VB. NET

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Magnus ?sterberg - 31 Dec 2004 12:41 GMT
Is there any way to determine the CAPS LOCK state in VB. NET, without
calling any VB6-style Windows API?
Herfried K. Wagner [MVP] - 31 Dec 2004 13:37 GMT
"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.

Signature

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

Tom Dacon - 31 Dec 2004 17:06 GMT
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");

}

> Is there any way to determine the CAPS LOCK state in VB. NET, without
> calling any VB6-style Windows API?
Herfried K. Wagner [MVP] - 31 Dec 2004 19:13 GMT
"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.

Signature

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

Tom Dacon - 01 Jan 2005 18:31 GMT
Thanks, Herfried.

TD

> "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.

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.