Handling Key Combinations in AWT

I am writing a GUI using AWT and need to handle keyboard input combinations (like holding down shift and pressing 8 to get the '*' character). How is this accomplished in AWT. I've tried various things, but it gives me the character on the bottom (instead of '*' I get '8'). I know how to do it in Swing, but I must write this using only the AWT classes.
Thanks

I'm not sure I've understood your problem, but could you try to keep special track of the extension keys (shift, ctrl, alt ...) by matching KEY_PRESSED and KEY_RELEASED events? If you have a KEY_PRESSED for shift but no KEY_RELEASED, you obviously have * instead of 8, right?

Similar Messages

  • How to get Multiple Key Combinations

    Hi,
    I am trying to get the event for multiple key combinations, ie some thing like "*Ctrl + I + M*" or "*Alt + A + S + D*".
    For two key combinations ( like Ctrl+I or Ctrl+M) i am able to get, but for more than two keys combinations, can someone give an idea how to get it.
    I tried with both KeyCodeCombination and KeyCharacterCombination.
    Below is a quick example to check for the key combination demo.
    import javafx.application.Application;
    import javafx.event.EventHandler;
    import javafx.scene.Scene;
    import javafx.scene.control.Label;
    import javafx.scene.input.KeyCharacterCombination;
    import javafx.scene.input.KeyCode;
    import javafx.scene.input.KeyCodeCombination;
    import javafx.scene.input.KeyCombination;
    import javafx.scene.input.KeyEvent;
    import javafx.scene.layout.StackPane;
    import javafx.scene.paint.Color;
    import javafx.stage.Stage;
    public class KeyCombinationDemo extends Application {
         Stage stage;
         Scene scene;
         StackPane root;
         public static void main(String[] args) {
              Application.launch(args);
         @Override
         public void start(Stage stage) throws Exception {
              this.stage = stage;
              root = new StackPane();
              root.getChildren().add(new Label("Enter any Key"));
              this.scene = new Scene(root, Color.LINEN);
              stage.setTitle(this.getClass().getSimpleName());
              stage.setWidth(600);
             stage.setHeight(600);
             stage.setScene(this.scene);
             stage.show();
              final KeyCombination keyComb1=new KeyCodeCombination(KeyCode.I,KeyCombination.CONTROL_DOWN);
              final KeyCharacterCombination keyComb2 = new KeyCharacterCombination("M",KeyCombination.CONTROL_DOWN);
              this.scene.addEventHandler(KeyEvent.KEY_RELEASED, new EventHandler<KeyEvent>() {
                   @Override
                   public void handle(KeyEvent event) {
                        if(keyComb1.match(event)){
                             System.out.println("Ctrl+I pressed");
                        }else if(keyComb2.match(event)){
                             System.out.println("Ctrl+M pressed");
    }Thanks in Advance.
    Regards,
    Sai Pradeep Dandem.

    Hi John,
    Thanks for the prompt response.
    I tried the way you suggested and it worked well !! Thanks :)
    But, still i am expecting a direct way to handle this. :p
    Anyway here is code which i modified accordingly
    final String keyCombination1 = "_ALT_E_O";
    final String keyCombination2 = "_ALT_E_P";
    final String keyCombination3 = "_CONTROL_H";
    final StringBuilder key = new StringBuilder();
    this.scene.addEventHandler(KeyEvent.KEY_PRESSED, new EventHandler<KeyEvent>() {
         @Override
         public void handle(KeyEvent event) {
              String codeStr = event.getCode().toString();
              if(!key.toString().endsWith("_"+codeStr)){
                   key.append("_"+codeStr);
    this.scene.addEventHandler(KeyEvent.KEY_RELEASED, new EventHandler<KeyEvent>() {
         @Override
         public void handle(KeyEvent event) {
              if(key.length()>0){
                   if(key.toString().equals(keyCombination1)){
                        System.out.println("Key Combination 1 pressed");
                   }else if(key.toString().equals(keyCombination2)){
                        System.out.println("Key Combination 2 pressed");
                   }else if(key.toString().equals(keyCombination3)){
                        System.out.println("Key Combination 3 pressed");
                   key.setLength(0);
    });Thanks & Regards,
    Sai Pradeep Dandem

  • How i can Find primary key combination?

    Hi,
    I have small doubt how i can find primary key combination for a record in siebel application.( For example Opportunity list applet or Account list applet or etc.. what is the primary key combination and how i can find that combination for a particular record)
    Thanks & Regards

    Hi
    From the applet Identify the Business Component (BC)
    From the BC idnetify the table, and the property user key sesuence will give you the proper combination. Column conflic_id is used for handling remote synchronization.
    For BC based on S_PARTY, such as COntact, the table mentionned in User PRop will give your the main table used in this case.
    Best Regards
    EvtLogLvl

  • Only xterm does key combinations properly

    I've been installing some vim plugins lately, and I've noticed that whenever I try to do Control+Foo or Alt+Bar I never get it to work.
    According to some users in #vim on FreeNode this has to do with how vim handles input, but one of them mentioned something about xterm working better than my current terminal emulator, gnome-terminal.
    So I fired up xterm, and indeed the plugins that previously didn't work due to their keybindings being stuff like Alt+1 started working.
    The main reasons for which I currently choose gnome-terminal over xterm are zooming in/out, terminal transparency and link opening.
    I've heard that urxvt does most of these things, but it has got the same problem with key combinations, so there is no real reason at the moment for me to switch.
    My questions are the following:
    Why does xterm manage to understand mentioned commands but not any other terminal I've tried?
    Are there any terminals that people know will support key combinations as well as xterm?
    If so, is there any terminal that does the three things I like in gnome-terminal?

    That might work, but I would need some way to get hold of what I should I write to represent the key combinations.
    I've tried showkey but I only get "Couldn't get a file descriptor referring to the console".

  • Change the font color of a text field in a table by key-combination

    I want to change the font color of a text field in a table (single cell only) on pressing a key combination. Does anybody know how to do this.
    I have a lot of data in a table. During an evaluation of the data in a meeting I want to change the color of the text depending on the result of the meeting. (for example: High risk = CTRL+R makes the text red).
    I know how to change the color using a button, but I do not want to add a button after each cell. For this reason I would like to do it on a key combination that alway refers to the active cell.
    Many thanks for your help in advance.
    Marcel

    Hi,
    I don't think you can use the ctrl key like that as those shortcuts will be intercepted by Reader (ctrl-R toggles the ruler display on / off).  You also might have trouble updating the color while you still have focus on it.  You can use the shift key in a similar way, so if you only have lower case characters in the text fields then you can do something like;
    if (xfa.event.shift)
        switch (xfa.event.change)
            case "R":
                this.fontColor = "255,0,0";
                break;
            case "O":
                this.fontColor = "255,102,0";
                break;
            case "G":
                this.fontColor = "0,255,0";
                break;
        xfa.event.change = ""; // ignore character
    If you need uppercase characters maybe you can have one button to set "review mode" and test that on the if (xfa.event.shift) line.  But again it wont take effect until you have tabbed out of the field.
    Regards
    Bruce

  • Today I tried to shutdown my computer and a window popped up saying that my computer could not shut down because the mail application was open, it wouldn't close, so I used a key combination to force mail to quit and now I can't log in. Help?

    Okay, so I have been having trouble with my mail application all week. The window refused to open and would not quit. Today, I tried to shut down my mac and a pop up window told me that I was unable to shutdown because mail was open. After using a key combination, I successfully was able to quit mail with force quit. Then I was able to shut down with out a problem. However, upon rebooting, my computer refused to let me loggin. I put in my password correctly but then the rainbow pinwheel showed up and stalled for a minute and then my screen flashed and the gray screen reappeared, expecting a password. I tried turning it off and back on again with no luck. I also reset my password after reading a similar discussion, but I still can't log in. How can I fix this?

    Startup - Gray, Blue or White screen at boot, w/spinner/progress bar
    Startup Issues - Resolve
    Startup Issues - Resolve (2)
    Avast! Uninstall

  • Is there a way to create a custom shortcut key to paste my email address?  I would like to be able to press a key combination that will paste whatever I set it to, i.e. my email address.

    Is there a way to create a custom shortcut key to paste my email address?  I would like to be able to press a key combination that will paste whatever I set it to, i.e. my email address.

    There are multiple ways to do similar things. One, built into the system, is to use text replacement. See:
    http://www.tuaw.com/2009/12/31/mac-101-making-text-replacement-work/
    There are other programs you can buy that can do the job in different ways, such as TextExpander. You could also just create a clipping file by dragging your e-mail address to somewhere like the desktop, and then you can simply drag that file to wherever you like to insert your e-mail address there.

  • Key combination Ctrl-Home Ctrl-End not working.

    vim has a default binding for <Ctrl-Home> goes to the beginning of the file and <Ctrl-End> for the end.
    However, I couldn't get these key combinations to work for me. And I've consulted the #vim channel on freenode.
    They said it maybe a problem that the terminal I'm using caught the key and didn't send it to vim, but I find this conjecture hard to believe, because I've since been testing several terminals including xfce's default, roxterm, tilda, lxterminal, lilyterm ... and none of them working.
    Later when I reboot I found that, even under the pure console (tty), the combination still doesn't work !
    So this must be a problem from the original key mapping itself, and not latter stuffs like xfce, terminals and editors etc...
    can anyone help me fix this ? I've also seen the wiki articles but unfortunately they aren't very helpful.

    The <C-{Home,End,Left,Right}> key combinations work in Xterm, but not in urxvt. All of the terminals that I recognize mentioned above are all VTE based terminals. This thread here:
    https://bugs.launchpad.net/ubuntu/+sour … +bug/89660
    is showing a lot of people with gnome-terminal, also VTE based, as not working either. It's definitely a terminal issue.
    The following page explains how to get Vim to recognize key combos that are usually trapped or unmapped by the terminal:
    http://vim.wikia.com/wiki/Mapping_fast_ … rminal_Vim

  • The "Quit all applications" key combination no longer works in Lion

    The standard Mac OS key combination to "quit all applications" no longer works in Lion. It only quits some of them some of the time - not all of them all of the time. Could this have something to do with the other "no Save-As" problem?
    Either way, it's yet another backwards step - one of several in Lion that are cumulatively slowing down and intefering with my workflow.
    I fear someone may jump in here and explain that this is one of the great new features and that it's my fault for being too dumb to appreciate it.....

    Your workflow is valuable to us; your opinions help us solve problems.

  • Importing Key Combinations of a Lookup table.

    Hi, I have created a lookup table which is equivalent to a check table in R3. For example table named, SPT (Special Procurement Type), Which has a key combination (Composite Keys) in R3 itself and the keys are Plant + Procurement Type and so in MDM Look table both keys are defined as display fields. The problem comes in automating the import. In IM source, both key fields are separate fields, I tried combining the field using Partion, but Automap is not working and so the import automation process. Any thoughts/advices on tackling this issue is appreciated.
    Thanks
    Job.

    Hi Job,
    IF u  combine the fields in partition and then if try to do value mapping automatically,then it is not possible .There u have to map manualy .Automap in value mapping can be done only when values are not combination but single.
    Like
    Source----
    Destination
    abc----
    <null>
    def----
    abc
    xyz----
    def
    xyz
    But if it is like:
    Source----
    Destination
    abc,12----
    <null>
    def,23 -
    abc,12
    def,23
    in above case it is a combination so not possible.
    I hope u im able to make u understand.
    If this has helped u then do Reward points.
    Regards,
    Neethu Joy
    Edited by: Neethu joy on Dec 31, 2007 3:17 PM
    Edited by: Neethu joy on Dec 31, 2007 3:19 PM
    Edited by: Neethu joy on Dec 31, 2007 3:24 PM

  • Creation of Condition table & assigning in Key Combination(FV11)

    Dear all,
    I have created a new Condition table(M/03) for Plant/Vendor Code/Tax code/Material,and i am getting the condition table in the key combination in FV11,and maintained,getting the values in the condition table.But my problem is i am not getting the maintained values in my Purchase Order.Please give any suggestions to solve this problem
    Regards,
    PR

    To get the values in PO, maintain the condition records in MEK1.
    FV11 is for tax calculation conditions
    Regards

  • Control key combinations in Keyboard Shortcuts

    I want to use the Control key plus letters, such as Ctrl-H, for shortcuts within Keyboard Shortcuts. I appreciate that such combinations are normally used by EMACS but I fail to understand what's happening in the Keyboard Shortcuts section of my Keyboard panel in System Prferences. It allows me to enter the Control key plus letter as my required shortcut but the shortcut never works. Any other shortcut, using other modifiers, even in combination with the Control key works fine. Now I have other utilities, such as FastScripts and Spark that allow me to use such combinations, so why can't they be used in Keyboard Shortcuts?
    If anyone else has this problem and knows of an answer it would be much appreciated!

    Well, the Keyboard Shortcuts panel doesn’t show the warning triangle as shown for other conflicts. Shouldn't the panel reject such key combinations if they're not available? Instead it shows them as being OK. I would have thought it reasonable to use such key combinations in non-EMACS applications anyway. Also, why is it that other utilities make it possible to use them? Most odd. I'll just have to use other methods I suppose!

  • Cant start up on my Macbook pro. All I get is a grey spinning wheel. Tried all the Startup key combinations and nothing works. I reset the NVRAM and nothing. I booted with start up disk , ran disk repair and all is ok. Tried to re-install OS but when I ge

    Can not start up on my Macbook pro. All I get is a grey spinning wheel. Tried all the Startup key combinations and nothing works. I reset the NVRAM and nothing. I booted with start up disk , ran disk repair and all is ok. Tried to re-install OS but when I get to designating drive its blank. When I go to startup disk there is a "?" mark. When I restart under startup disk search for a drive it still comes up with nothing.  Before I got the grey spinning wheel I had a locked screen. Could not move curser or click on anything. Finally just shut down. Thank you in advance for any help!

    Shouldn't still have a 'beachballing'... if the drive is being found and the system is trying to boot from it but is having problems, I would suggest looking over ds store's user tip - Step by step to fix your Mac.
    It's likely either something corrupt in your system files or a failing hard drive. But follow ds's steps until you find the cause of the problem.
    Good luck,
    Clinton

  • Two printers need to be maintained for one key combination

    Hi Experts,
    Requirement:-For one condition record two print out has to be determined on different printers.
    As per my understanding we can maintain only one printer for any key combination here as per the requirement if some one has any idea if we can maintain two printers for the same key combination.
    Regards,
    Dharmesh

    Hi,
    You cannot  assign two printers to one single combination of Condition record.
    This functionality is not possible.
    regards,
    santosh

  • Setting up key combination trapping to kill X server?

    How can I trap a key combination (ctrl+alt+backspace) in order to kill the X-server with these?

    Actually, I may have marked this as answered too quickly...
    So I followed the guide at the back of the getting started manual, and set everything up as follows:
    - PCI ethernet card is set up as the connection to the outside world. It is plugged into a switch which connects to a wall jack. In Network under System Preferences, it is set up as the first internet conection to try. It has a static IP address, and is set up to use the organization's DNS servers. It is NOT plugged into the upstream port, but is instead in port #9. The light on the router is on.
    - Built-in wireless is set up to be the internal connection. It is plugged into the upstream slot on anouther switch. It has a static IP address, and is set up to use the organization's DNS servers. The light on the router is on, so it appears there is a connection.
    - A different computer is plugged into the second switch, which a static IP address and to use the organization's DNS servers.
    So basically, unlike in the scenario in the manual, I am not using the OS X Server for DNS, DHCP or NAT services. That should, if anything, simplify it.
    The firewall service is started, and is set to allow all traffic in and out, no problems. Nice and simple to start.
    The server has an okay connection to the outside world via the PCI ethernet card. I can ping other machines and load web pages. I cannot, however, access the machine connected to the router which is connected to the built-in ethernet. Likewise, that machine has no access to either the OS X Server or the outsideworld.
    How does OS X Server decide which ethernet card is to be connected to the outside world, and which is for the internal firewall? Is the confusion possible because I'm connected to two routers?

Maybe you are looking for

  • Flex compilation error: line exceeds 32k span

    Hi All, I am trying to execute my application being developed in VC7.0 (nw04s sneak preview version) using tabbed layers. I have 3 layers and has the following UI components 1 tab/layer: input form 2 tab/layer: table control 3 tab/layer: table contro

  • Disabled last view settings

    I am trying to display a pdf from simple html to a specific page such as <a href="test.pdf#page=55&view=Fit">Page 55</a><br> This works fine but if I change to other pages from within the IE Browser window, exit and return utilizing this href I get r

  • Error while cloning database using RMAN

    hi there, Here is our setup: OS: Solaris 5.9 Database:9.2.0.3 While cloning test database from our production database using RMAN, we happen to get the following error.. RMAN-00571: =========================================================== RMAN-005

  • How to take a non metrics column from one fact to different subject area details level?

    I have a requirement in OBIEE , I have two fact tables W_AP_INV_DIST_F and W_PURCH_COST_F. In my subject area I am using all facts from W_AP_INV_DIST_F table, But I need one more column as per client's requirement. I searched the column RELEASE_NUM f

  • KXML Parser

    Hi all, This question is for those of you who know and used the kXML parser (http://developers.sun.com/techtopics/mobility/midp/articles/parsingxml/) How can I use it in order to parse binary data which is stored in an XML (in the standard way, of co