|
Okay: The final say from it not working is, that it works for right and left, but you would have to hold the SpaceBar to make the pictureBox go right without stopping. Help?
- "Achieving all knowledge does not mean achieving all wisdom." some wise dude
- I love D-flat!
|
|
|
|
|
I would do something along these lines:
- use a Windows.Forms.Timer, it ticks on the GUI thread
- no lock is needed, all key/timer actions run on GUI thread, without
interrupting each other.
- timer ticks all the time, at 10 times the autorepeat frequency (overclocking)
- each key is synchronized to the overclocked timer. with the const values shown
it would start repeating after 900 to 1000 msec.
- you can easily choose different start repeat and repeat times...
Dictionary<Keys,int>m_keys = new Dictionary<Keys,int>();
Windows.Forms.Timer m_timer = new Windows.Forms.Timer();
const int initialWait = 10;
const int repeatWait = 10;
const int overPeriod = 100;
public Constructor() {
m_timer.Interval=initialWait;
m_timer.Start();
m_timer.Tick += new EventHandler(autoRepeatTick);
}
private void m_KeyDown(object sender, KeyEventArgs e) {
Keys key=e.KeyCode;
handleKey(key);
if (keys.ContainsKey(key)) {
m_keys[key]=overClocking;
} else {
m_keys.Add(key, overClocking);
}
}
private void m_KeyUp(object sender, KeyEventArgs e) {
keys.Remove(e.KeyCode);
}
private void autoRepeatTick(object sender, ElapsedEventArgs e) {
foreach (Keys key in m_keys.Keys) {
int wait=m_keys[key]-1;
if (wait<=0) {
handleKey(key);
wait=repeatWait;
}
m_keys[key]=wait;
}
}
private void handleKey(Keys key) {
... game code
}
Above code is indicative, but has not been tested!
Luc Pattyn [Forum Guidelines] [My Articles]
this months tips:
- before you ask a question here, search CodeProject, then Google
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get
- use PRE tags to preserve formatting when showing multi-line code snippets
|
|
|
|
|
I kind of like this idea, but I feel like combining both keys into one action will improve performance, especially if making a game. Giving each key "it's own timer" as indicated in this post will give the "expected" result, but you will have to render your scene up to twice as much as if you handled the keys together at once. This could result in your game hanging if it is a realtime sort of game with lots of detailed shapes. The alternative may make the buttons lag or double press in a short time (depending on implementation), but it will prevent rendering up and right separately. Just a suggestion.
Jeff
|
|
|
|
|
It all depends on the numbers I guess: with a 1-second autorepeat, I would type much faster
than that, making your render argument moot.
If the repeatWait delay were much less than indicated earlier, you might indeed want
to synchronize them. But by all means, while holding down a first key, a short hit of a
second key should never fire twice. So its autorepeat should only start when more than an
entire timer period has elapsed. (In my code, you could adjust the initial wait to achieve
this).
And if the repeatWait becomes less than say 20 msec (that's the repeatWait, not the
initialWait!) it would not matter any more since the player would be unable to notice...
Luc Pattyn [Forum Guidelines] [My Articles]
this months tips:
- before you ask a question here, search CodeProject, then Google
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get
- use PRE tags to preserve formatting when showing multi-line code snippets
|
|
|
|
|
Direct Input
Christian Graus - Microsoft MVP - C++
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
Why not use the Shift or Control keys for a different state?...you can have both of those simultaneously...that's what they are for, to modify the state of a keypress.
|
|
|
|
|
Hi,I need a Sample code for setting for example ReportViewer1.BorderStyle in my source file.when i run my project in C#,there is a error message for this code: ReportViewer1.BorderStyle="solid".How can i write code like this without using ReportViewer Toolbar before running the project to define my Report Page setup as like as BorderStyle seting ,page setup setting for example my papaer size to be A4 and margin setting and other properties of my Report without defining this properties at running time or design time only with writing code in source file in my report from ?
thanks
D.riazi
|
|
|
|
|
I know this message isn't too C# oriented, but how would I program my own computer, as in what tools would I need to start from scratch, but also for modifying Windows. (Is that even legal?) I know this is WAY, WAY, WAY, WAY, WAY, WAY, WAY above my head, I'm just curious in case I lose my stupidity. Thanks for any suggestions/comments. (unless they're mean!)
- "Achieving all knowledge does not mean achieving all wisdom." some wise dude
- I love D-flat!
|
|
|
|
|
|
Haha. Funny, aren't we?
- "Achieving all knowledge does not mean achieving all wisdom." some wise dude
- I love D-flat!
|
|
|
|
|
Starting from scratch, as in bypassing windows, is a major, major task. I'd say forget it.
You can't modify windows, you don't have the source code.
Christian Graus - Microsoft MVP - C++
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
Okay; thanks for a simple quick answer.
- "Achieving all knowledge does not mean achieving all wisdom." some wise dude
- I love D-flat!
|
|
|
|
|
MasterSharp wrote: but how would I program my own computer, as in what tools would I need to start from scratch
A compiler in the language of your choice.
MasterSharp wrote: but also for modifying Windows.
In what way would you like to modify windows?
MasterSharp wrote: Is that even legal?
That depends on what you regard as modify. I suppose there is nothing stopping you modifying any part of windows, but is it wise. Windows has sophisticated systems in place that allow you to hook into the OS without modifying it.
Upcoming FREE developer events:
* Developer! Developer! Developer! 6
* Developer Day Scotland
My website
|
|
|
|
|
What kind of compilers? Any known. Thank you for your answers so far!
- "Achieving all knowledge does not mean achieving all wisdom." some wise dude
- I love D-flat!
|
|
|
|
|
There are many ways to do this. Although all the ways are very hard, and are not to be taken lightly.
The most common way, is to start by writing in Assembly. You write a simple program that runs in the boot-sector of the hard drive, a very small section that CMOS runs upon boot. That program would have to start your new OS. Sounds pretty simple in theory. Problem is, the program that goes in the boot-sector has to be written in certain ways, and has to tell enough about what you are doing next to be able to actually do what you want to do next, and all of this has to be done in VERY little space.
That solution required Assembly, a language used pretty much only for server solutions and fine fine tuning and optimization today. Today you can code in pretty good Assembly by actually writing in C. Assembly is processor level code, writing in actual processor commands, this is very hard and not human readable, so using one of these C based compilers would be recommended.
I was thinking about messing around and creating my own DOS like OS, millions of little problems come up, like a bunch of driver issues.
The best way to accelerate a Macintosh is at 9.8m/sec² - Marcus Dolengo
|
|
|
|
|
Hi!
I get this message:
Error 1 Missing partial modifier on declaration of type 'VAControls.SchedulerXmlNode'; another partial declaration of this type exists C:\Documents and Settings\Yossi_Tubis\My Documents\Visual Studio 2005\Projects\VASchedular\VASchedular\SchedulerXmlNode.cs 8 11 VASchedular
how can i know where this decleration exists so i will change it??
|
|
|
|
|
It is probably in the designer. Do you have a SchedulerXmlNode.designer.cs file? This error indicates you declared the class VAControls.SchedulerXmlNode twice, but one of the two declarations is missing the "partial" keyword (like "public partial class VAControls...")
Jeff
|
|
|
|
|
OK so say that I have 2 points
StartPoint = new Point(50,50);
End Point = new Point(175, 195);
k, now I need to add distance to this line and calculate the new End Point.
Any Help wold be appreciated
"All of us who served in one war or another know very well that all wars are the glory and the agony of the young."
Gerald Ford
|
|
|
|
|
Let sp be StartPoint and ep be EndPoint...
1. Calculate the current length
float len = sqrt(exp(sp.X - ep.X, 2) + exp(sp.Y - ep.Y, 2));
2. Calculate the ratio of the new length to the old length
float rat = newLen / len;
3. Using the rule that scaling a triangle maintains length ratios...
Point resultEp = new Point(rat * (ep.X - sp.X) + sp.X, rat * (ep.Y - sp.Y) + sp.Y);
then the line from sp to resultEp will have length newLen.
Jeff
|
|
|
|
|
OK - this is a maths problem not a programming one. Anyway, you shouldn't look at applying just a distance - you really need to apply a direction, i.e. treat it as a vector, because the new point will depend on the direction as well as the distance.
|
|
|
|
|
|
i want to create a small application that gives a txt file from user and send it to a fax number!
how can i use FaxModem to do it?
is there any function,dll,component...??
Imposible is Imposible...
|
|
|
|
|
A quick google search reveals some good hits, include this CP article[^].
|
|
|
|
|
Hi,
I am currently designing a project, which requires dynamic plugins to be added to the main application, which get loaded during runtime.
However, I am not sure about the correct way to implement this. Is reflection the right way to go about this? Does anyone know a good example or site where I can find further info on dynamic plugin handling in c# code?
Thanks...
|
|
|
|
|