Jump to content

  • Log In with Google      Sign In   
  • Create Account

#ActualGixugif

Posted 20 January 2012 - 09:56 PM

I am aware that there is a bug, a 12 or 13 year old bug, that exists on Linux and probably other Unix based systems, that certain ways of detecting when a key is pressed or released do not function the way one would expect. I am also aware there are a few ways around this and I have gone so far to attempt to implement this solution that can be viewed here: http://stackoverflow.../4679195/596359

The problem is that this does not seem to fix anything. The first question someone will ask I believe I can anticipate. I placed this code in a ".java" file named "RepeatingKeyEventsFixer.java". This file is in "../src/com/example/". To use it in my code I have put the following lines at the beginning of my main() method:

RepeatingKeyEventsFixer repeatingkeyeventsfixer = new RepeatingKeyEventsFixer();
repeatingkeyeventsfixer.install();

Still, when I press down a key, it tells me it's being pressed down and held, but it will also say it is being released with just about the same frequency. Does anyone have any idea what I may have done wrong? I have also posted this on StackExchange with poor results. I'll post the link here in case the way I phrased things there could help any more: http://stackoverflow.../8948238/596359

The following code is the code I am using to test if a key has been released or not. I appreciate the time any takes to consider my question.

addKeyListener(new KeyAdapter() {
	public void keyPressed(KeyEvent e){
		processKey(e);
	}
	public void keyReleased(KeyEvent g){
		processKeyReleased(g);
	}
}
...
private void processKeyReleased(KeyEvent g){
	int keyCode = g.getKeyCode();
	if(!isPaused && !gameOver){
		if(keyCode == KeyEvent.VK_LEFT || keyCode == KeyEvent.VK_RIGHT){
			System.out.println("released");
			player.stopLooping();
		}
	}
}

#3Gixugif

Posted 20 January 2012 - 09:56 PM

[There seems to be a problem with the "



I am aware that there is a bug, a 12 or 13 year old bug, that exists on Linux and probably other Unix based systems, that certain ways of detecting when a key is pressed or released do not function the way one would expect. I am also aware there are a few ways around this and I have gone so far to attempt to implement this solution that can be viewed here: [url="http://stackoverflow.com/a/4679195/596359"]http://stackoverflow.../4679195/596359[/url]



The problem is that this does not seem to fix anything. The first question someone will ask I believe I can anticipate. I placed this code in a ".java" file named "RepeatingKeyEventsFixer.java". This file is in "../src/com/example/". To use it in my code I have put the following lines at the beginning of my main() method:



[code]RepeatingKeyEventsFixer repeatingkeyeventsfixer = new RepeatingKeyEventsFixer();

repeatingkeyeventsfixer.install();[/code]



[color=#000000]Still, when I press down a key, it tells me it's being pressed down and held, but it will also say it is being released with just about the same frequency. Does anyone have any idea what I may have done wrong? I have also posted this on StackExchange with poor results. I'll post the link here in case the way I phrased things there could help any more: [url="http://stackoverflow.com/q/8948238/596359"]http://stackoverflow.../8948238/596359[/url][/color]



[color=#000000]The following code is the code I am using to test if a key has been released or not. I appreciate the time any takes to consider my question.[/color]



[code]addKeyListener(new KeyAdapter() {

    public void keyPressed(KeyEvent e){

	    processKey(e);

    }

    public void keyReleased(KeyEvent g){

	    processKeyReleased(g);

    }

}

...

private void processKeyReleased(KeyEvent g){

    int keyCode = g.getKeyCode();

    if(!isPaused && !gameOver){

	    if(keyCode == KeyEvent.VK_LEFT || keyCode == KeyEvent.VK_RIGHT){

		    System.out.println("released");

		    player.stopLooping();

	    }

    }

}

#2Gixugif

Posted 20 January 2012 - 09:54 PM

I am aware that there is a bug, a 12 or 13 year old bug, that exists on Linux and probably other Unix based systems, that certain ways of detecting when a key is pressed or released do not function the way one would expect. I am also aware there are a few ways around this and I have gone so far to attempt to implement this solution that can be viewed here: http://stackoverflow.../4679195/596359

The problem is that this does not seem to fix anything. The first question someone will ask I believe I can anticipate. I placed this code in a ".java" file named "RepeatingKeyEventsFixer.java". This file is in "../src/com/example/". To use it in my code I have put the following lines at the beginning of my main() method:

[font=Consolas, Menlo, Monaco,]RepeatingKeyEventsFixer[/font][color=#000000][font=Consolas, Menlo, Monaco,] repeatingkeyeventsfixer [/font][/color][color=#000000][font=Consolas, Menlo, Monaco,]=[/font][/color][color=#000000][font=Consolas, Menlo, Monaco,] [/font][/color][font=Consolas, Menlo, Monaco,]new[/font][color=#000000][font=Consolas, Menlo, Monaco,] [/font][/color][font=Consolas, Menlo, Monaco,]RepeatingKeyEventsFixer[/font][color=#000000][font=Consolas, Menlo, Monaco,]();[/font][/color]
[color=#000000]repeatingkeyeventsfixer[/color][color=#000000].[/color][color=#000000]install[/color][color=#000000]();[/color]
[color=#000000]
[/color]
Still, when I press down a key, it tells me it's being pressed down and held, but it will also say it is being released with just about the same frequency. Does anyone have any idea what I may have done wrong? I have also posted this on StackExchange with poor results. I'll post the link here in case the way I phrased things there could help any more: http://stackoverflow.../8948238/596359

The following code is the code I am using to test if a key has been released or not. I appreciate the time any takes to consider my question.

[color=#000000][font=Consolas, Menlo, Monaco,]addKeyListener[/font][/color][color=#000000][font=Consolas, Menlo, Monaco,]([/font][/color][font=Consolas, Menlo, Monaco,]new[/font][color=#000000][font=Consolas, Menlo, Monaco,] [/font][/color][font=Consolas, Menlo, Monaco,]KeyAdapter[/font][color=#000000][font=Consolas, Menlo, Monaco,]()[/font][/color][color=#000000][font=Consolas, Menlo, Monaco,] [/font][/color][color=#000000][font=Consolas, Menlo, Monaco,]{[/font][/color]
    [color=#00008B]public[/color] [color=#00008B]void[/color] keyPressed([color=#2B91AF]KeyEvent[/color] e){
        processKey(e);
    }

    [color=#00008B]public[/color] [color=#00008B]void[/color] keyReleased([color=#2B91AF]KeyEvent[/color] g){
        processKeyReleased(g);
    }
}

...

[color=#00008B]private[/color] [color=#00008B]void[/color] processKeyReleased([color=#2B91AF]KeyEvent[/color] g){

    [color=#00008B]int[/color] keyCode = g.getKeyCode();

    [color=#00008B]if[/color](!isPaused && !gameOver){
        [color=#00008B]if[/color](keyCode == [color=#2B91AF]KeyEvent[/color].VK_LEFT || keyCode == [color=#2B91AF]KeyEvent[/color].VK_RIGHT){
            [color=#2B91AF]System[/color].out.println([color=#800000]"released"[/color]);
            player.stopLooping();
        }
    }
}

#1Gixugif

Posted 20 January 2012 - 09:53 PM

I am aware that there is a bug, a 12 or 13 year old bug, that exists on Linux and probably other Unix based systems, that certain ways of detecting when a key is pressed or released do not function the way one would expect. I am also aware there are a few ways around this and I have gone so far to attempt to implement this solution that can be viewed here: http://stackoverflow.../4679195/596359

The problem is that this does not seem to fix anything. The first question someone will ask I believe I can anticipate. I placed this code in a ".java" file named "RepeatingKeyEventsFixer.java". This file is in "../src/com/example/". To use it in my code I have put the following lines at the beginning of my main() method:

[font=Consolas, Menlo, Monaco,]RepeatingKeyEventsFixer[/font][color=#000000][font=Consolas, Menlo, Monaco,] repeatingkeyeventsfixer [/font][/color][color=#000000][font=Consolas, Menlo, Monaco,]=[/font][/color][color=#000000][font=Consolas, Menlo, Monaco,] [/font][/color][font=Consolas, Menlo, Monaco,]new[/font][color=#000000][font=Consolas, Menlo, Monaco,] [/font][/color][font=Consolas, Menlo, Monaco,]RepeatingKeyEventsFixer[/font][color=#000000][font=Consolas, Menlo, Monaco,]();[/font][/color]
[color=#000000]repeatingkeyeventsfixer[/color][color=#000000].[/color][color=#000000]install[/color][color=#000000]();
[/color]
Still, when I press down a key, it tells me it's being pressed down and held, but it will also say it is being released with just about the same frequency. Does anyone have any idea what I may have done wrong? I have also posted this on StackExchange with poor results. I'll post the link here in case the way I phrased things there could help any more: http://stackoverflow.../8948238/596359

The following code is the code I am using to test if a key has been released or not. I appreciate the time any takes to consider my question.

[/color][color=#000000][font=Consolas, Menlo, Monaco,]addKeyListener[/font][/color][color=#000000][font=Consolas, Menlo, Monaco,]([/font][/color][font=Consolas, Menlo, Monaco,]new[/font][color=#000000][font=Consolas, Menlo, Monaco,] [/font][/color][font=Consolas, Menlo, Monaco,]KeyAdapter[/font][color=#000000][font=Consolas, Menlo, Monaco,]()[/font][/color][color=#000000][font=Consolas, Menlo, Monaco,] [/font][/color][color=#000000][font=Consolas, Menlo, Monaco,]{[/font][/color]
	[color=#00008B]public[/color] [color=#00008B]void[/color] keyPressed([color=#2B91AF]KeyEvent[/color] e){
		processKey(e);
	}

	[color=#00008B]public[/color] [color=#00008B]void[/color] keyReleased([color=#2B91AF]KeyEvent[/color] g){
		processKeyReleased(g);
	}
}

...

[color=#00008B]private[/color] [color=#00008B]void[/color] processKeyReleased([color=#2B91AF]KeyEvent[/color] g){

	[color=#00008B]int[/color] keyCode = g.getKeyCode();

	[color=#00008B]if[/color](!isPaused && !gameOver){
		[color=#00008B]if[/color](keyCode == [color=#2B91AF]KeyEvent[/color].VK_LEFT || keyCode == [color=#2B91AF]KeyEvent[/color].VK_RIGHT){
			[color=#2B91AF]System[/color].out.println([color=#800000]"released"[/color]);
			player.stopLooping();
		}
	}
}

PARTNERS