|
hey, i want to know how to disable certain keys from being pressed if another one has been pressed before, i am making a game which moves the player accress the screen, and there are certain restrictions to move the player, hence my question... i have programmed my keys below :
private void Form1_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Up)
{
Player.Direction = 1;
}
if (e.KeyCode == Keys.Right)
{
Player.Direction = 3;
}
if (e.KeyCode == Keys.Down)
{
Player.Direction = 2;
}
if (e.KeyCode == Keys.Left)
{
Player.Direction = 4;
}
}
I want to disable the "Keys.Up" if the "Keys.Down" is pressed but if another key is pressed, for example, the "Keys.Left" then the "Keys.Up" is re-enabled .....
Thanks in advance :P
|
|
|
|
|
To disable a key, set e.Handled = true before you return.
See here[^]
Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together.
|
|
|
|
|
same code as you have - perfect, on whatever key you want to hit, have a boolean, check if you want it to be enabled/disabled based on that boolean,
put return False where you want the key to do nothing
otherwise leave out the return false
MVC
|
|
|
|
|
Don't mean to step on the other guys who answered, but it looks like you're trying to have Up and Down cancel each other out (And Left+Right)... This'll take a little more than what you have now, but not very much.
The easiest way would probably be to just keep track of which keys are currently pressed. Now, you can use API calls to query them directly, but if you want to stick to simple events, here's one way to do it:
1) Create a dictionary mapping keys to a boolean
2) Whenever a key you're watching is pressed OR released (Handle the KeyUp event too!), set its value in that dictionary to true (Pressed) or false (Not pressed)... If you want to make this more readable and intuitive, you can even use an enum instead of a boolean.
3) Whenever you make a change to the dictionary, run a separate function to test the current key states... Then you can check for things like if (IsKeyPressed[Keys.Left] && !IsKeyPressed[Keys.Right]) ...
There are plenty of other ways to do this, but this is one of the simplest... If you want to be more efficient, you can use a single flags-type enum value instead of a dictionary, and use binary operations to set and unset the various components:
[Flags]
enum ArrowKeyStates {
None = 0,
Left = 1,
Up = 2,
Right = 4,
Down = 8,
UpLeft = 3,
UpRight = 6,
DownLeft = 9,
DownRight = 12
}
MyKeyState |= ArrowKeyStates.Left;
MyKeyState ^= ArrowKeyStates.Left;
|
|
|
|
|
thanks everyone, helped me a lot,
|
|
|
|
|
i need a formula through which i can increase the font size of records in details section by passing value like 12,13,14
|
|
|
|
|
What is this to do with C#?
Just say 'NO' to evaluated arguments for diadic functions! Ash
|
|
|
|
|
Hey,What you will do with value 12,13,14. your requirement is not clear.
we can help you when you try to help us by clear formatting of your question.
|
|
|
|
|
|
in the report, set the font size to the expression and then give the parameter as a value in the report.
lets make this clear.
add Report parameter->font_size(int) - from the report menu;
then set the report parameter value from c#;
then in the report select the textbox and then set its font size to expression ;
then select parameters(font_size)..!
postback for any clarifications..
|
|
|
|
|
Hello All,
How can I read from standard input and write to standard output. System.Diagnostics.Process.StandardInput's MSDN reference didn't help as it separately starts the process and then redirects the Standard Input/Output but what If the process is already running and called my Application to feed it some data. Here's an example to make things a bit clear:
I am simply using Unix pipes i.e. cat command in cygwin (A Linux like Environment for windows) that basically just reads standard input and print to standard output. following is the command:
% cat input/sample.txt | src/csharp/maptest
But that doesn't seems to work. Any solutions?
Thanks in advance.
AliAmjad(MCP)
First make it Run THEN make it Run Fast!
|
|
|
|
|
Are you looking for System.Console.In and System.Console.Out ?
In .net, detecting redirection and pipes is a little tricky, but I posted some code on my blog -- look under my proile.
|
|
|
|
|
Instead of calling master page, XYZ.aspx page is showing
Collapse
<%@ Page Language="C#" MasterPageFile="~/Master1.master" Title="abc" %>
and not showing master page contents. Moreover, on running localhost masterpages and .aspx pages are not showing any problem and easily master page contents are accessible by webform
|
|
|
|
|
Can u please check that u r having more than one web.config file in ur project. if it is there remove the unwanted web.config file and run the project .
|
|
|
|
|
Can you please use your keyboard, txt speak is not appreciated.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Just to back up what Mycroft says, remember that many of the Codeproject users are not native English speakers. If you use txtspeak, they cannot use a dictionary to work out what you are saying.
As a result, use of txtspeak is discouraged.
Plus, it looks childish!
Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together.
|
|
|
|
|
This is CLEARLY not a C# question. Post it in the correct forum.
.45 ACP - because shooting twice is just silly ----- "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "The staggering layers of obscenity in your statement make it a work of art on so many levels." - J. Jystad, 2001
|
|
|
|
|
verify your web.config please.
♫ 99 little bugs in the code,
99 bugs in the code
We fix a bug, compile it again
101 little bugs in the code ♫
|
|
|
|
|
hello all
can someone explain me step by step the "nural network face detection algorithm" that infact what is it saying. so i will be able to implement it.
i studied it but i don't understand it.
please someone help me.
or any links or suggestions will be appreciated.
thanks
|
|
|
|
|
I think it is too tough to explain something like this in a forum. You will have to spend some time getting hang of it. This[^] IMHO is the best place to begin with.
|
|
|
|
|
Sure, but noone is going to type up an entire book just for you, espectially in a blog post.
Serisouly, this is a HUGE topic that cannot be explained in a couple of forum posts.
|
|
|
|
|
so then can i find the step by step explanation somewhere?
as the first reply told me about a link. i am going to study it and thanks a lot.
if any other link or suggestion etc.
please help me.
|
|
|
|
|
There is no "step-by-step" for a topic that is so complex that you need to know the math behind it all. You're not filling a ComboBox here...
|
|
|
|
|
You've already been told how to go about this. Nobody is going to spoon feed you the solution on how to do this; tell me, are you trying to do this for a dissertation or thesis? If so, you have to be able to demonstrate that you understand the subject you are trying to write about, and you will end up doing yourself a disservice which could result in you not passing your course.
|
|
|
|
|
actually i have taken "face detection and recognition" as my final semester project. and I have to implement it without any library.
if i didn't implement it so i can't pass the course.
|
|
|
|