Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. How to know whether CapsLock is on

How to know whether CapsLock is on

Scheduled Pinned Locked Moved Visual Basic
questionwinformsjsontutorial
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Marc 0
    wrote on last edited by
    #1

    hi all, how do i know whether capslock is on? i do not mean whether is is pressed, something like this this doesnt work

    class form1 'keypreview is true
    inherits form
    'windows forms designer generated code etc

    private CapsOn as boolean = false

    protected overrides sub onkeydown(e as keyeventargs)
    mybase.onkeydown(e)
    if e.keycode = keys.capslock then capson = not capson
    end sub

    end class

    beacuse when capslock is on before app starts stuff goes the wrong way around... does anyone have a idea? a api or something? thanks, mouzik

    R 1 Reply Last reply
    0
    • M Marc 0

      hi all, how do i know whether capslock is on? i do not mean whether is is pressed, something like this this doesnt work

      class form1 'keypreview is true
      inherits form
      'windows forms designer generated code etc

      private CapsOn as boolean = false

      protected overrides sub onkeydown(e as keyeventargs)
      mybase.onkeydown(e)
      if e.keycode = keys.capslock then capson = not capson
      end sub

      end class

      beacuse when capslock is on before app starts stuff goes the wrong way around... does anyone have a idea? a api or something? thanks, mouzik

      R Offline
      R Offline
      rudy net
      wrote on last edited by
      #2

      .Net framework didn't encapsulate all the Windows APIs yet so you will have to call the following windows api: Private Declare Function GetKeyState Lib "user32" (ByVal virtKey As Integer) As Short Then call it. For example: if GetKeyState(Keys.CapsLock) = 1 then capson = true

      M 1 Reply Last reply
      0
      • R rudy net

        .Net framework didn't encapsulate all the Windows APIs yet so you will have to call the following windows api: Private Declare Function GetKeyState Lib "user32" (ByVal virtKey As Integer) As Short Then call it. For example: if GetKeyState(Keys.CapsLock) = 1 then capson = true

        M Offline
        M Offline
        Marc 0
        wrote on last edited by
        #3

        thanks rudy! although it didnt work at first, i got it working in the end: Private Declare Function GetKeyState Lib "user32" (ByVal virtKey As Integer) As Integer and to call it: CapsOn = CBool((GetKeyState(Keys.CapsLock) And 65535) - 65408)) thanks again!

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups