[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1342
  • Last Modified:

MAC and the CAPS LOCK key

Using Netscape 3 on a MAC:

The CAPS LOCK key seems to be ignored in TextArea and TextFields that are drawn in the Applet window.  TextFields/Areas drawn in a Dialog box recognize the CAPS LOCK key.  And I've seen inconsistent behavior in this regard with additional Frames.  I can't determine what the significant difference is between those frames that work and thos that don't.  Has anyone seen this?  Have a explanation or work around?
0
mlimotte
Asked:
mlimotte
1 Solution
 
jpk041897Commented:
Take a look at:

http://www.geocities.com/Athens/7077/Java072.htm

this page contains a class, called Event05, that subclasses textField.

This particular class has the ability of monitoring the Events that happen in a textField and displaying them (I used it succesfully to limit the ammount of characters that can be inputed to a textField).

By using this class you can figure out if the CAPS LOCK key is actualy sending anything or not. (and what its sending).

Once you have figured this out, I can suggest a workarround:

Modify the Event05 class to behave like an almost normal textField but add a CapsLock flag and an if statment that tests for the flag.

Inside the if block, you can implement code that adds the ASCII offset for a normal and Cap'd letters. (I forget the actual value, 27 I think) but it can be calculated with 'a' -'A')

This class can also aid you in figuring out whats going on with the other question you posted.

For reference, and to cut back a little time on the modifed version you would need if this suggestion actualy solves your problem, I'm posting the code I used to limit the characters in a textField. Of course, the same logic applies to textAreas.

import java.awt.*;

//Define a custom TextField class that can respond to events.
//  Note that this class extends TextField.
class TF extends TextField{

  int maxCount = 5;
  int count = 0;       
  TF(String inString, int MaxCount){
     setText(inString);
     maxCount = MaxCount;
  }//end constructor

  //The following event handler method handles events at the
  // component level as opposed to the container level.
  public boolean handleEvent(Event evObj){
 
    switch(evObj.id){
      case Event.KEY_PRESS :
        if (count < maxCount){
             char[] c = new char[1];
             c[0]= (char) evObj.key;
             String s = new String(c);
             setText(getText() + s);
             count++;
          }
          break;
      default : //catch and display all other event types here
          break;
    }//end switch
    return super.handleEvent(evObj);
  }//end handleEvent() in class TF
 
}//end class TF
//===================================================================

You can easily modify this class to acomplish a simulation of th CAPS LOCK key, provided it realy is sending sata to the app.
0
 
mlimotteAuthor Commented:
The CAPS LOCK key alone does not produce an event.  But, your suggestion prompted me to look at the events and I realized that when the CAPS LOCK key is down the proper CAPITALIZED ascii value is sent (i.e. A=97 as opposed to 65), but the shift modifier is not sent.  Certain MAC AWT components apparently lowercase the ascii value unless the shift modifier is on.  So, my solution was to resend these bad events with the shift modifier.

I gave a B grade, becuase the answer was not completely correct, but it did suggest an avenue of investigation.

I had already used this method with the COMMAND key, but apparently no event is generated for these key presses.

0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now