Solved

MAC and the CAPS LOCK key

Posted on 1997-06-05
2
1,322 Views
Last Modified: 2010-05-19
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
Comment
Question by:mlimotte
2 Comments
 
LVL 6

Accepted Solution

by:
jpk041897 earned 80 total points
ID: 1221269
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
 
LVL 1

Author Comment

by:mlimotte
ID: 1221270
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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

For customizing the look of your lightweight component and making it look opaque like it was made of plastic.  This tip assumes your component to be of rectangular shape and completely opaque.   (CODE)
INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now