Java-Gaming.org    
Featured games (79)
games approved by the League of Dukes
Games in Showcase (477)
Games in Android Showcase (107)
games submitted by our members
Games in WIP (536)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Disabling alt when on a JFrame?  (Read 3092 times)
0 Members and 1 Guest are viewing this topic.
Offline Renoria

Junior Member




...


« Posted 2009-01-18 12:44:22 »

When I press ALT on a JFrame, and I press the down or up arrow key, a menu appears. How do I disable this so I can actually use ALT in game?

Thanks.

Offline SimonH
« Reply #1 - Posted 2009-01-19 04:01:56 »

When I press tab on a JFrame, and I press the down or up arrow key, a menu appears. How do I disable this so I can actually use alt in game?

What exactly are you asking? (alt+tab==bad move!)

People make games and games make people
Offline Renoria

Junior Member




...


« Reply #2 - Posted 2009-01-19 10:18:34 »

Ooops lol, I meant alt. You know when you press it, it shows a menu on a JFrame? I need that to be disabled so I can use alt for jump.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline SimonH
« Reply #3 - Posted 2009-01-19 14:57:57 »

I've used alt keys in JFrames with no problem... Can you post a cutdown example demonstrating the problem?


People make games and games make people
Offline pifreak

Senior Newbie





« Reply #4 - Posted 2009-01-19 17:41:24 »

I think I know what the problem is, copying and pasting code before getting to know what it does.

You added the Alt + key combinations to your JMenu without knowing it.


say this is a start button on your menu, having Alt+A being enabled to use it

1  
2  
3  
4  
start_button = new JMenuItem("Both text and icon",
                         new ImageIcon("images/start.gif"));
start_button.setMnemonic(KeyEvent.VK_A);
menu.add(start_button);


You shouldn't have that this line of code because it enables Alt for JMenu use.

1  
start_button.setMnemonic(KeyEvent.VK_A);


"A" being changeable

if it still pops up a menu on your game after taking out all of these, there might be one more thing into your menu.

post your code here like SimonH recommended.



Offline Renoria

Junior Member




...


« Reply #5 - Posted 2009-01-20 03:28:54 »

I don't have a JMenu. Its the default menu:



I've also tried setFocusTraversalKeysEnabled(false)
Offline SimonH
« Reply #6 - Posted 2009-01-20 03:55:16 »

Hmmm.. JFrame doesn't have a default menu - you have to set one...
Can't really help unless you post your code!

People make games and games make people
Offline pifreak

Senior Newbie





« Reply #7 - Posted 2009-01-20 04:13:21 »

exactly why I was wondering if he used JFrame and JMenu...

JFrame is just a blank frame until you add menus and text and such
Offline i30817

Junior Member





« Reply #8 - Posted 2009-01-20 05:05:57 »

I've had this happen, but i don't know where (still have).

Are you sure its not something laf related? because if it is and i can find the key its out of there.

Edit: To clarify, i don't have a jmenu either, just a Jframe+custom Jcomponent + ocasional JDialog + ocasional JPopupMenu.
Offline Renoria

Junior Member




...


« Reply #9 - Posted 2009-01-20 07:16:08 »

My code:

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
33  
34  
35  
36  
37  
38  
39  
40  
41  
42  
43  
44  
45  
46  
47  
48  
49  
50  
51  
52  
53  
54  
55  
56  
57  
58  
59  
60  
61  
62  
63  
64  
65  
66  
67  
68  
69  
70  
71  
72  
73  
74  
75  
76  
77  
78  
79  
80  
81  
82  
83  
84  
85  
86  
87  
88  
89  
90  
91  
92  
    public void init() {
        try {
            processor = new PacketHandler();
        } catch (Exception e) {
            Console.w = false;
            e.printStackTrace();
            ErrorDialog ed = new ErrorDialog(Console.getWindow(), "Server unavailable", "Connecting to the server failed.");
            ed.setLocation(getScreenCenter(ed));
            ed.setTitle("Server Unavailable");
            ed.getCloseButton().addActionListener(new ActionListener() {
                @Override public void actionPerformed(ActionEvent ae) {
                    System.exit(0);
                }
            });
            ed.setVisible(true);
            Console.getWindow().dispose();
            Console.getApplication().setWindow(null);
            return;
        }
        initComponents();
        setMinimumSize(new Dimension(800, 600));
        setMaximumSize(new Dimension(800, 600));
        setResizable(false);
        ImageTransparencyTransformer t = ImageTransparencyTransformer.getInstance();
        setIconImage(
                t.filter(getToolkit().createImage(getClass().getResource("resources/images/icon.png")))
                );
        setLocation(getToolkit().getScreenSize().width / 2 - getSize().width / 2, getToolkit().getScreenSize().height / 2 - getSize().height / 2);
        addWindowListener(new WindowAdapter() {
            @Override public void windowClosing(WindowEvent we) {
                close();
            }
        });
        setTitle("Renoria");
        try {
            macro = new Robot();
        } catch (Exception e) {
            e.printStackTrace();
            ScreenManager s = ScreenManager.getInstance();
            s.restoreScreen();
            ErrorDialog d = new ErrorDialog(this, "GUI Error", "Creating the User Interface failed.");
            d.setVisible(true);
            this.setVisible(false);
        }
        macro.mouseMove(getToolkit().getScreenSize().width / 2,
                      getToolkit().getScreenSize().height / 2);
        Cursor c = getToolkit().createCustomCursor(getToolkit().createImage(""),
                                                   new Point(0,0), "");
        setCursor(c);
        setAlwaysOnTop(true);
        cursor = getToolkit().createImage(getClass().getResource("resources/images/cursor.png"));
        cursor = t.filter(cursor);
        defaultCursor = cursor;
        final AbstractMedia am = this.media;
        final MainWindow wi = this;
        addKeyListener(new KeyListener() {
            @Override public void keyPressed(KeyEvent key) {
                if (key.getKeyCode() == KeyEvent.VK_F12) {
                    takeScreenShot("Renoria-");
                    return;
                }
                if (key.getKeyCode() == KeyEvent.VK_ENTER) {
                    if (key.isAltDown()) {
                        key.consume();
                        ScreenManager s = ScreenManager.getInstance();
                        if (s.getFullScreenWindow() != null) {
                            s.restoreScreen();
                        } else {
                            s.setFullScreen(dis);
                        }
                        return;
                    }
                }
                if (media != null)
                    media.keyPressed(key);
            }

            public void keyTyped(KeyEvent key) {
                if (media != null)
                    media.keyTyped(key);
            }

            public void keyReleased(KeyEvent key) {
                if (media != null)
                    media.keyReleased(key);
                if (key.getKeyCode() == KeyEvent.VK_ESCAPE && Console.testing) {
                    //System.exit(0);
               }
            }
        });
        setFocusTraversalKeysEnabled(false);
    }
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Renoria

Junior Member




...


« Reply #10 - Posted 2009-01-20 07:26:50 »

Just did an experiment. using even this code:

1  
2  
3  
4  
5  
   public static void main(String[] a) {
      JFrame w = new JFrame("this sux");
      w.setSize(300, 300);
      w.setVisible(true);
   }


creates that menu.
Offline Addictman

Senior Member


Medals: 3
Projects: 1


Java games rock!


« Reply #11 - Posted 2009-01-20 10:05:41 »

Must be some system settings on your end. Your ALT-click behaviour is equivalent to the typical right-click behaviour in the title bar (or iconized window on taskbar). Weird though, this popup menu does not have hotkeys on my system.
Offline SimonH
« Reply #12 - Posted 2009-01-20 18:11:54 »

this popup menu does not have hotkeys on my system.
Nor mine! Strange...

People make games and games make people
Offline Abuse

JGO Coder


Medals: 11


falling into the abyss of reality


« Reply #13 - Posted 2009-01-20 18:18:27 »

Just did an experiment. using even this code:

1  
2  
3  
4  
5  
   public static void main(String[] a) {
      JFrame w = new JFrame("this sux");
      w.setSize(300, 300);
      w.setVisible(true);
   }


creates that menu.

What OS? Vista?

In XP pressing alt does indeed give focus to the title bar, altering the behaviour of subsequent key presses. (up & down cursors will cause the menu you describe to appear, while other keys will be consumed by the windowing system, and depending upon the key being pressed may return the focus back to the application)

Without native code I don't think there is anything you can do about it.
Although... you do receive a key event for the initial 'Alt' key press. Perhaps if you issued a requestFocus event in response to this keypress, it would interrupt the windowing system's title bar gaining focus.

Make Elite IV:Dangerous happen! Pledge your backing at KICKSTARTER here! https://dl.dropbox.com/u/54785909/EliteIVsmaller.png
Offline SimonH
« Reply #14 - Posted 2009-01-20 18:32:11 »

Hey, Renoria, could you try Jetp4k (uses arrow keys, has alt as a fire key) and see if that screws up? If not I'll get you the source code.

People make games and games make people
Offline Abuse

JGO Coder


Medals: 11


falling into the abyss of reality


« Reply #15 - Posted 2009-01-20 19:19:35 »

Hey, Renoria, could you try Jetp4k (uses arrow keys, has alt as a fire key) and see if that screws up? If not I'll get you the source code.

Yep, in XP i'm seeing the issue he's described.

Make Elite IV:Dangerous happen! Pledge your backing at KICKSTARTER here! https://dl.dropbox.com/u/54785909/EliteIVsmaller.png
Offline bienator

Senior Member




OutOfCoffeeException


« Reply #16 - Posted 2009-01-20 19:46:11 »

i am not sure if this will work but have you tried to consume all alt key events?

//end of key pressed method
if (key.isAltDown()) {
       key.consume();
}

Offline Ultraviper

Junior Newbie





« Reply #17 - Posted 2009-01-20 21:51:08 »

I get the same problem in Vista64 Home Premium.
Pressing alt+arrow at the same time does nothing but pressing alt by itself, then up or down by itself, brings up the annoying menu.
Offline Renoria

Junior Member




...


« Reply #18 - Posted 2009-01-20 23:56:54 »



Yeah, just played JetP4k on vista with java webstart. Just got this annoying menu to popup. Also, pressing right or left then alt causes you to keep moving right/left without stop even if you're not pressing any keys.

Anyway, would using a robot to press Alt again work?
Offline SimonH
« Reply #19 - Posted 2009-01-21 02:28:58 »

Yeah, just played JetP4k on vista with java webstart. Just got this annoying menu to popup. Also, pressing right or left then alt causes you to keep moving right/left without stop even if you're not pressing any keys.
Dammit! Mind you, I put the alt==fire thing in just for mac users...
Best I can suggest is that you don't use the alt key in the way that you are - is there a sensible alternative?

People make games and games make people
Offline Renoria

Junior Member




...


« Reply #20 - Posted 2009-01-21 04:32:31 »

will a robot work? Or is the key never registered by a keyListener?
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

Riven (13 views)
2014-07-29 18:09:19

Riven (10 views)
2014-07-29 18:08:52

Dwinin (10 views)
2014-07-29 10:59:34

E.R. Fleming (28 views)
2014-07-29 03:07:13

E.R. Fleming (10 views)
2014-07-29 03:06:25

pw (40 views)
2014-07-24 01:59:36

Riven (39 views)
2014-07-23 21:16:32

Riven (27 views)
2014-07-23 21:07:15

Riven (28 views)
2014-07-23 20:56:16

ctomni231 (59 views)
2014-07-18 06:55:21
HotSpot Options
by dleskov
2014-07-08 03:59:08

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:58:24

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:47:22

How do I start Java Game Development?
by ra4king
2014-05-17 11:13:37

HotSpot Options
by Roquen
2014-05-15 09:59:54

HotSpot Options
by Roquen
2014-05-06 15:03:10

Escape Analysis
by Roquen
2014-04-29 22:16:43

Experimental Toys
by Roquen
2014-04-28 13:24:22
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!