Updating caps lock and num lock status

I need to keep track of the status of the caps lock and num lock keys in a status bar of my frame.
I get the current status with a code like this
Toolkit toolkit = Toolkit.getDefaultToolkit();
numLockState = toolkit.getLockingKeyState(KeyEvent.VK_NUM_LOCK);
capsLockState = toolkit.getLockingKeyState(KeyEvent.VK_CAPS_LOCK);
fireChangeEvent();
where fireChangeEvent() updates a label in the status bar. The code is invoked when any of the caps lock and num lock keys are pressed (while the window has the focus) and when the window is activated. This code works while the window has the focus (i.e. the status of the keys if correctly tracked). It does not work correctly when the window is activated.
Specifically the following scenario fails:
- The window has focus and the state of the keys if correctly reported by the code above (say caps lock up, num lock
up);
- The window loses focus, i.e., another (non java) window gains the focus;
- The user presses any of the two keys (say the caps lock key);
- The window regains focus.
When the latter event happens the code above is invoked (as a consequence of the window being activated) but it continues to report the status of the keys at the time the focus was lost by the window (caps lock up, num lock up).
It seems that the toolkit does not automatically updates its internal status if a key is pressed when the java window does not have the focus. If I press the caps lock key (so that it returns to the up state) after the window has regained focus the status is updated and the new state is correctly reported. I need to manually realign the status by pressing the keys to have them correctly reported by the toolkit.
Some ideas on how to have correct key status even after the window looses the focus?
Thanks.

Specifically the following scenario fails:
- The window has focus and the state of the keys if correctly reported by the code above (say caps lock up, num lock
up);
- The window loses focus, i.e., another (non java) window gains the focus;
- The user presses any of the two keys (say the caps lock key);
- The window regains focus.
When the latter event happens the code above is invoked (as a consequence of the window being activated) but it continues to report the status of the keys at the time the focus was lost by the window (caps lock up, num lock up).sorry! i tried this in a JFrame windowActivated() and i got the desired result it breaks your senario.
the only is though it is not sensing the keyStrokes but if window looses focus because of another window gains focus it changes the values when it get focus next by ne means.
Provide a short executable code might be the problem lies there.

Similar Messages

  • CAPS lock status in Linux

    Hi,
    I'm trying to get the CAPS lock status in Java to display the same to the user in my application. I've used the code
    Toolkit.getDefaultToolkit().getLockingKeyState(KeyEvent.VK_CAPS_LOCK) .
    This works properly in Windows but throws UnsupportedOperationException in Linux. Can you help me to get the CAPS lock state in Linux.
    Regards
    Ruban

    Moderator action: Moved from Generics
    db

  • Since downloading update Caps Lock is backwards on my keyboards (both laptop and desk top)

    I downloaded the the latest Firefox update and couldn't seem to log into any of my favorite sites. This was on my laptop. Now on my desktop I am experiencing the same thing.
    My login is fine because I select from the dropdown menu. But if I have not saved my password for sites like my bank account etc. I cannot log in. I finally figured out it was the key board setting. With caps lock on lowercase, but with caps lock off upper case!
    IMPORTANT NOTE: laptop is Windows 7, Desktop is Linix!

    In two years of daily participation in these forums, I don't recall ever seeing this reported before. So no, it isn't a "known problem". I think what I'd do in your shoes is sit down and type a couple of pages of text while sitting on my left hand, to completely disrupt all my typing habits and force me to do everything with my right hand. If the problem continued to occur under those circumstances, I'd figure it was real and probably a keyboard fault. If not, I'd pay closer attention to my left hand when typing.

  • Pavilion dv7-1245dx caps light and num lock light blink

    Got a Hp pavilion dv7-1245dx. When going to start the computer after hitting the power button the all the lights come on on the volume bar, the fan runs and then the caps light and the num lock light start blinking. I can tell if there is a specific number of blinks in a sequence or if it is just one blink repeatedly.  This computer is less than 2 yrs old. Please help

    I have already tried all the powering down options and nothing is helping. I really need this thing!

  • Caps, Scroll and Num Lock Notification - How to disable

    Hi,
    When i hit either my caps, scroll or num lock on my keyboard have this small notification popup and have problem disabling the function.
    How will i go about to disable this?

    C:\Program Files (x86)\Hewlett-Packard\Shared
    Find hpCaslNotification.exe and rename it.
    Then open task manager and kill this process.
    You have to rename the file, simplly killing won't work because hphotkeymonitor service runs it every time you press caps lock, scroll lock or num lock.

  • Keyboard suddenly requires caps on and num lock on in order to type

    But with the caps on it types lower case and won't work if both keys are not pushed. Have I changed keyboards or pushed some code without knowing it?

    Sounds like you need some maintenance done. But on the chance that you caould correct the issue yourself, Try a PMU and PRAM reset. If this doesn't work, try the hardware test on the disk that came with your computer.
    To reset the PRAM, hold down Option, Apple, O, and F at startup. Wait for two startup chimes.
    To use the hardware test insert the disk that came with your computer and hold down D on startup.
    If this doesn't work, you will need to take it in for service.
    Best Regards,
    David Finell

  • Laptop won't boot caps light and Num light blink

    My Ts2-1375dx won't boot after I have shut it off and turned it back on. I get the cap & num lock lights blinking once. I remove the powercord, battery and all attached peripherals, hold the on button for 30 seconds reconnect the power and try booting again. Although this works (maybe after 1-3 tries) I don't believe that this is the way you should have to boot the computer. I also see lots of the same problem with the solution being the method I use. WHY IS THERE NO PERMANT FIX?!?!
    This question was solved.
    View Solution.

    Please try understanding the root cause for the issue by understanding the LED blink codes from the following weblink:
    HP Notebook PCs - Computer Does Not Start and the LEDs Blink or the Computer Beeps
    Provides procedures for resolving problems identified with blink codes or beep codes during startup
    I am an HP employee.
    Regards,
    Vidya
    Make it easier for other people to find solutions, by marking my answer “Accept as Solution” if it solves your problem.
    ***Click on "Thumbs up" button to the bottom right side of my post to say thanks!***

  • How can i bind something to caps lock in AwesomeWM?

    Recently i've aquired new notebook which doesn't have caps_lock, num_lock and scroll_lock LEDs, so i decided to put keyboard layout indicator to system tray.
    Currently i am using Xorg config to set XkbLayout and XkbOptions (like so http://paste.pocoo.org/show/478789/ ).
    I tried first widget from http://awesome.naquadah.org/wiki/Change_keyboard_maps but soon realized that it does not detect layout change in any way, so i would like to bind kbdcfg.switch function to caps_lock, but i can't find any documentation on binding something to caps_lock.
    Also i've noticed a strange thing, when i change my layout with this function i am unable to use shortcuts that use latin letters. They are obviously remapped to by сyrillic, but they do work if i change my layout with caps_toggle. Why do the work with caps_toggle, and how can i make them work with kbdcfg.switch?

    blin wrote:
    filam wrote:Is there a reason you're not using xmodmap? You may also want to read the Extra Keyboard Keys in Xorg article.
    The only reason i have for not using xmodmap is, i don't understand how it can help me, with the task i have. The other article didn't help me either.
    Did you read the "How to find capslock status?" thread?
    blin wrote:Is suspect the answer is not what you want because your question is not very clear. I understand that you have a keyboard that is lacking certain keys. What is it that you want to achieve? Let some key act as capslock?
    I had to read the OP twice to understand it. I didn't notice that he wrote "LED" in the first sentence. What he wants is for his Awesome status bar to display the current activity (i.e. on/off) of the Caps Lock, Num Lock and Scroll Lock keys. He does not need to remap any keys.
    Edit: Check Retrieving CAPS LOCK info using Xlib or just do a Google search for "linux caps lock status -map -disable".
    Last edited by filam (2011-09-20 19:43:45)

  • ****PLEASE HELP ME SOMEONE**** PLEASE - Re: ON SCREEN CAPS LOCK INDICATOR

    can someone please help me before i pull all of my hair out.
    i have windows vista - 64 bit - the HP IQ500 touchsmart with a wireless keyboard.
    in the systray the num caps and scroll lock appears as little blue boxes (when on).
    everynow and again they simply disapper.
    i researced how to activate them again but cant remember how to do it.
    there is a way without having to mess with the registry and without downloading any program
    i just cant remember how. i know wherever it is...you ultimately get 3 boxes that you can check in order to turn the options back on.
    i am not talking about toggling, or sound, or mscofig and then boot.
    does anyone know the steps to turn the caps scroll and num lock indicator in teh sys tray back on
    oh, and right clicking on the toolbar and going to the notificiation area is not what i am referring to either.
    I checked in the control panel programs and the hp on screen caps lock indicator etc program is there.
    I reinstalled it nonetheless and confirmed it is installed properly
    When I right click on the notification area I do to properties/notification area/customize
    There are two lists there
    1. Current Items and
    2. Past Items
    For some reason I see caps lock - scroll lock and num lock under the past items
    There you are also able to change the status of the items to either Hide wne active, hide or show
    All three (caps/num/scroll) are SHOW
    I click apply OK then apply
    I restart the computer and nothing. The on screen caps lock indicator is still not in the notification area/systray area
    I repeat teh steps to ensure that the three have the SHOW option chosen and they are.
    So....
    Program is installed
    Items are check for SHOW
    Restart was done
    Ohhh and also...I went to MSCONFIG and made sure that the HP Keyboard Program was selected/check mark as one of the start up programs.
    There in a run command to activiate the 3rd party program (hp onscreen indicator program)
    When you enter the run command that I cant remember...you then get this option where there are three check boxes...one next to num lock - one next to caps lock and one for scroll lock.
    Once you check/select the boxes/options you want...presto they appear in the sys tray/notification area.
    I just cant remember the run command it to save my life.
    Please....put my mind to ease...cause I am losing it!
    I just cant seem to "walk away"...must be my OCD :-(
    Thanks

    NO.
    We are all iPhone users just like you.
    Apple has no blacklist.
    You can contact your carrier and see if they offer such a service.
    You cannot block it at all.
    Sorry

  • Caps Lock LED incorrect when changing modifier keys

    Hello,
    I remapped Caps Lock and Ctrl keys via keyboard settings (they're now flipped). Unfortunately the Caps Lock LED is still being activated by the "old" Caps Lock key (which is now the Ctrl key). This means that whenever I hit Ctrl (using the Caps Lock key) the Caps Lock LED changes its status.
    This is rather annoying as it ends up being in random state and tells me nothing about the actual Caps Lock status. Is there a way to fix this?
    Thanks!

    Hello:
    I suggest you call Applecare with a warranty issue.  The KB has a one year Apple warranty.  I would not waste any more time trying additional things.  You have already tried everything I would suggest.
    Barry

  • My HP Pavillion dv4 has a black screen and blinking Caps and Num lock

    BEFORE anyone says to take out everything and press the start button for however many seconds, i've tried that. I've also tryed counting blinks, but there seems to be no pause in blinks, thus continuous blinking. 
    SO, recently i have updated my laptop, i let it shut off but i did not choose for it to restart. Today when i tried to turn it on, the screen was black, did not turn on and the caps lock and the num lock have been blinking continuosly, without pattern. The touch screen volume and such is also on and after a few seconds the fan turns on. There is no loud beep, just the regular startup soft beep. So, i would like to know, if anyone knows what i can do, before i have to go and pay to fix this thing.

    i have took it to the apple store, i am out of warranty and they said it is a hardware problem, god knows whats causing the black screen it is fine when on as i got it fixed at a local phone shop but when the phone dies then there is no bringing it back to life.

  • Continousl​y flashing caps and num lock dv7

    I've got a vista dv7-2120sa that I recently bought off ebay as spares repairs to use the keyboard, fan and battery on my long term laptop which is a windows 7 dv7-2230sa. I'm assuming the parts are all compatible but the ebay laptop is in very nice condition so would like to try and get it working. Thing is it only gets as far as a blank screen, the fan works, the disc drive works ie I can hear it moving, lights are on but the caps lock and num lock blink continuously at intervals of approx 3-4 seconds - any ideas?

    I should think you might find the Product key on the lable on the bottom) on a notebook of this vintage.
    The product key is a 25 character-number code and can be used to install the original Operating System.  If you cannot find, use, or decipher the product key, you can buy a copy of Windows 7 for the computer and then install the HP software from the system's webpage.
    HP dv7-2120sa > Solve a Problem > Start-up / Shutdown > Start-up / Boot-up
    Calls:
    Consumer Notebooks - Testing for Hardware Failures (Windows 7, Vista)
    Extra Reference:
    Notebooks - Computer Does Not Start (Windows 7, Vista, XP)
    Depending on when the notebook was manufactured (mid 2009 and more recent), you might be able to update the diagnostics to use the UEFI set.  The main advantage of using this method is that of the GUI (graphics interface).  You can live without it.  Assuming you can use it, you can install the UEFI onto a USB stick and use that to run the modules.
    Click the Kudos Star!
    It is a nice “Thank You” for the Experts who come to your aid.
    Kind Regards,
    Dragon-Fur

  • Windows 10 Caps Lock and Num Lock dosen`t work

    Hi guys,
    I have a problem to report, on asus k52de dosen`t work Light from the Caps and num lock .
    This problem appered yesterday when windows make the last update.
    If anybody is in the same problem like me please answer the solution.
    THX

    I've developed registry settings that both enable the "Filter Keys" feature in the Ease of Access center and use other values for which there are not UI fields to set repeat values to slow things down, but use values a little different
    than those provided by the UI.
    With this registry file the start of auto-repeat is slowed to 440 milliseconds, and the keys repeat at a reasonable rate of something around 30 per second. 
    http://Noel.ProDigitalSoftware.com/ForumPosts/Win10/Win10FastKeyboardRepeatFix.reg
    Here's what's inside the above:
    Windows Registry Editor Version 5.00
    [HKEY_CURRENT_USER\Control Panel\Accessibility\Keyboard Response]
    "Last Valid Wait"=dword:00000000
    "Last Valid Delay"=dword:000003e8
    "Last Valid Repeat"=dword:000001f4
    "Last BounceKey Setting"=dword:00000000
    "Flags"="59"
    "DelayBeforeAcceptance"="0"
    "AutoRepeatRate"="20"
    "AutoRepeatDelay"="440"
    "BounceTime"="0"
    The following registry file disables "Filter Keys" and returns Windows to the default settings.  If you employ the above, after the next build drop I suggest running the following and see if Microsoft has fixed the problem (they've acknowledged
    it and said it will be fixed in a future build).
    http://Noel.ProDigitalSoftware.com/ForumPosts/Win10/Win10KeyboardRepeatReturnToDefault.reg
    The above contains:
    Windows Registry Editor Version 5.00
    [HKEY_CURRENT_USER\Control Panel\Accessibility\Keyboard Response]
    "Last Valid Wait"=dword:00000000
    "Last Valid Delay"=dword:000003e8
    "Last Valid Repeat"=dword:000001f4
    "Last BounceKey Setting"=dword:00000000
    "Flags"="58"
    "DelayBeforeAcceptance"="0"
    "AutoRepeatRate"="500"
    "AutoRepeatDelay"="1000"
    "BounceTime"="0"
    If you're at all skeptical about running downloaded .reg files from other folks (as you should be), I encourage you to use the text yourself or download them and look inside with an editor before running them.
    -Noel
    Detailed how-to in my eBooks:  
    Configure The Windows 7 "To Work" Options
    Configure The Windows 8 "To Work" Options

  • Problem with Caps Lock and Num Lock after 10.5.1

    I noticed after updating to 10.5.1 my caps and num lock lights were on, i thought this odd as I did not push the buttons, pushing the buttons to turn the lights off however actually turns the caps and num lock features on.
    In short, the light is backwards! when caps is OFF the light is on and when caps is ON the light is OFF!
    the same is true for the num lock key/light...???
    anyone else notice this problem?

    Same exact problem... after updating I noticed that my numbers lock and caps lock were on. Didn't think much of it so I turned them off and then I notice that they are working in reverse. Caps lock on gives me lower case letters and numbers lock on I only get the symbols associated with that key above the number....mmmmm.
    Anyone found a fix yet? I have looked in preferences and other places but found no solution.

  • Num/Cap lock blinking and computer screen not starting

    ok. i have a HP pavilion entertainment pc dv7 notebook.
    1)    For the last 3 weeks my screen would turn off randomly. maybe once every other day or so on.  The computer would stay on and my ligths on the keyboard,( VOL bar, Multimedia buttons, Wifi button, Mute button, Caps lock and Num lock) .Only thing that would turn off is my Monitor. Sometimes when it turns off my speakers would make a status sound across the sound bar. But i can be on my computer for hours, or even leave my computer on for days with the screen open and it wont do anything.
    2)   then for that last few days i notice when i turn on my computer everything would turn on EXCEPT THE MONITOR. then i hold down the power button and turn it back on and it starts up fine.
    3)  Then yesterday when i tried turning it on. Same thing monitor wouldnt turn on but my NUM/Caps lock would blink. So again i would turn the laptop off , turn it back on and now its up and running
    I really rely on my computer so i was considering taking it to a local tech but i wanna know the issue so he doesnt give me some kinda Jive turkey story. I would just start rening a computer from Aarons rent but  dont think there computers are any good for my gaming. Starcraft 2, league of legends ecct.

    Hi,
    Please try a hard reset and see if it works.
    1. Power off your laptop
    2. Remove the a/c adapter, battery and everything that is attached to your laptop.
    3. Hold the 'POWER 'button down on your laptop for about 10 seconds.
    4. Plug in the a/c power supply (without battery) and power on.
     Please check the following link for more information:
         http://h10025.www1.hp.com/ewfrf/wc/document?docname=c01443366&cc=us&dlc=en&lc=en&jumpid=reg_R1002_US...
    Regards.
    BH
    **Click the KUDOS thumb up on the left to say 'Thanks'**
    Make it easier for other people to find solutions by marking a Reply 'Accept as Solution' if it solves your problem.

Maybe you are looking for