Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: GarageGothic on Fri 17/06/2005 10:58:22

Title: Is there any way to check for CAPS LOCK being activated?
Post by: GarageGothic on Fri 17/06/2005 10:58:22
I was wondering if there's any way to check for Caps Lock being on/off (like you can check for Shift being pressed)?
Title: Re: Is there any way to check for CAPS LOCK being activated?
Post by: naltimari on Fri 04/04/2008 03:05:46
Quote from: GarageGothic on Fri 17/06/2005 10:58:22
I was wondering if there's any way to check for Caps Lock being on/off (like you can check for Shift being pressed)?

I found out that IsKeyPressed(426) detects if the user pressed CAPS LOCK, but I guess there is no way to know whether if it is activated or not.
Title: Re: Is there any way to check for CAPS LOCK being activated?
Post by: Lee on Fri 04/04/2008 20:21:45
I'm not sure if this would work or not but could you create a routine to monitor the CAPS KEY being pressed (426) and use it to set a global f ???lag that says weather the CAPS are set or reset.
Title: Re: Is there any way to check for CAPS LOCK being activated?
Post by: DoorKnobHandle on Fri 04/04/2008 20:27:49
...which would work great unless the user starts the program with CAPS already on or unless the user decides to switch the CAPS-state in a game-situation where no key-presses are detected (in a Wait()-period for instance) - then the flag would be !true... ;)
Title: Re: Is there any way to check for CAPS LOCK being activated?
Post by: naltimari on Fri 04/04/2008 20:38:37
Quote
...which would work great unless the user starts the program with CAPS already on

Exactly. The ideal test for CAPS LOCK should be like mouse.Mode, or something, otherwise the state of CAPS LOCK is not accurate.

Besides that, IsKeyPressed() returns true only if the key is being pressed at the moment, so if you test for it occasionally, you might not get it, and if you test for it in rep_ex_always, you might risk setting the flag many times.

This naïve approach definetely does not work:


function repeatedly_execute_always()
{
  if (!capslock && IsKeyPressed(426))
    capslock = true;
  else if (capslock && IsKeyPressed(426))
    capslock = false;
}


because since it is executed many times per second, the flag is unset right after it was set, should the user hold the key down for more than 1/40 of a second... and most of us are not THAT fast to hold it for a shorter time.
Title: Re: Is there any way to check for CAPS LOCK being activated?
Post by: Khris on Fri 04/04/2008 20:57:22
A quick way to sort this out is to only set the flag after the key is released.
Title: Re: Is there any way to check for CAPS LOCK being activated?
Post by: naltimari on Fri 04/04/2008 21:22:41
Quote from: KhrisMUC on Fri 04/04/2008 20:57:22
A quick way to sort this out is to only set the flag after the key is released.

Hmm. It does not solve the 'initial state problem', but it's a good idea. How about this:


  if (IsKeyPressed(426))
    capsdown = true;
  else if (capsdown) {
    capslock = !capslock;
    capsdown = false;
  }


It works, but uses two 'flags'... any other ideas?
Title: Re: Is there any way to check for CAPS LOCK being activated?
Post by: Radiant on Fri 04/04/2008 23:18:10
You can possibly detect if the caps lock is on by requiring the user to press the 'A' key at some point, and reading whether it returns 'a' or 'A', and whether either shift key is held.
Title: Re: Is there any way to check for CAPS LOCK being activated?
Post by: naltimari on Sat 05/04/2008 00:23:04
Quote from: Radiant on Fri 04/04/2008 23:18:10
You can possibly detect if the caps lock is on by requiring the user to press the 'A' key at some point, and reading whether it returns 'a' or 'A', and whether either shift key is held.

Actually, this won't work, since the keycodes for lowercase and uppercase are the same (as per the current manual).
Title: Re: Is there any way to check for CAPS LOCK being activated?
Post by: Radiant on Sat 05/04/2008 01:04:17
Quote from: naltimari on Sat 05/04/2008 00:23:04
Actually, this won't work, since the keycodes for lowercase and uppercase are the same (as per the current manual).

Yes, but you can still use input boxes, both the one from the function and the one on GUIs.
Title: Re: Is there any way to check for CAPS LOCK being activated?
Post by: OneDollar on Sat 05/04/2008 09:25:14
But then you can't tell if they pressed the shift key to get a capital or not?
Title: Re: Is there any way to check for CAPS LOCK being activated?
Post by: monkey0506 on Sat 05/04/2008 20:11:20
Certainly there's a way for the system to register whether CAPS has been activated, so as to know whether to produce the lower or upper case characters whilst typing. So the question would become whether CJ could implement a hook into the system's check and return the result to AGS.

Clearly there's no built-in method in AGS yet to do this, but I think naltimari's solution would probably be a good workaround albeit no way of assuring the initial state. Perhaps in these sequences where you required a check of CAPS you could have a 'calibration' feature?

BTW naltimari, that's a smooth workaround. That may solve a problem I've been having...once I have a computer again! :-\
Title: Re: Is there any way to check for CAPS LOCK being activated?
Post by: TwinMoon on Sat 05/04/2008 20:29:42
Good to see you're still debating the nuts and bolts of AGS, monkey_05_06!

It's odd that the keycodes for a and A are the same.  I would think that A=65 and a=97, but AGS reads both keycodes as A.
Clearly when typing text into a textbox a and A are read as different characters. You might do something with this to check whether the capslock is pressed or not. I don't know if IsKeyPressed can be used when a text box is displayed.

The only other solution is to ask the player whether the capslock is on or off at the beginning ;)
Title: Re: Is there any way to check for CAPS LOCK being activated?
Post by: Radiant on Sat 05/04/2008 22:53:16
Quote from: TwinMoon on Sat 05/04/2008 20:29:42
It's odd that the keycodes for a and A are the same.  I would think that A=65 and a=97, but AGS reads both keycodes as A.
They're the same because they're key codes, not character codes. That's also why the left shift has a different code than the right shift, even though they're functionally the same.
Title: Re: Is there any way to check for CAPS LOCK being activated?
Post by: TwinMoon on Sun 06/04/2008 02:25:22
Hm.

Well, technically a is Shift-A. Ctrl-A also has a keycode.
Title: Re: Is there any way to check for CAPS LOCK being activated?
Post by: naltimari on Sun 06/04/2008 19:13:02
Quote from: Pumaman on Wed 30/01/2008 21:55:37
Changes in 3.0.1 Final:
* Added System.NumLock/CapsLock/ScrollLock properties

Wohoo!! Problem solved, I guess... Thanks, CJ!
Title: Re: Is there any way to check for CAPS LOCK being activated?
Post by: monkey0506 on Mon 07/04/2008 18:49:30
Heh,  CJ is a sneaky one indeed. Without even posting he corrected this issue behind all of our backs. :=

Makes AGS somewhat like a detective game...finding all the secrets hidden within! ;D