Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

MAC and the CAPS LOCK key

Posted on 1997-06-05
2
1,331 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Weekend adv creator 3 52
custom annotations 9 42
diffSum example 4 50
how to see all occupied ports on windows 10 laptop 15 76
By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:

856 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