Jump to content

How can you tell if caps lock is on?

2 replies to this topic

#1 ashnwill

  • Members
  • 5 posts

Posted 06 October 2016 - 06:26 PM

I need to be able to tell if caps lock is on so I can use the 'key' event and have it properly capitalize characters if caps lock is on. Is there any way to do this?

I can't just use the 'char' event.

#2 MKlegoman357

  • Members
  • 1,170 posts
  • LocationKaunas, Lithuania

Posted 06 October 2016 - 06:40 PM

Well, there's is no way of knowing it then. Why cannot you use the "char" event, which is meant just for this?

#3 Sewbacca

  • Members
  • 450 posts
  • LocationStar Wars

Posted 06 October 2016 - 07:03 PM

With the following code, you should be able to detect if caps lock is changed, but you need the char event, because if the computer starts or if the user left the computer, you can't know if he used caps:
function detectCapsChanged ()
  while true do
	local event, key = os.pullEvent()
	if event == 'key' and key == keys.caps then -- I dunno how exactly is the name in keys
	  CapsChanged() -- A local event handler

Edited by Sewbacca, 06 October 2016 - 07:04 PM.

1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users