473,378 Members | 1,401 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

Preventing Key/Mouse Events from Interruping Processing

Does anyone know a good method of preventing keyboard and mouse events from
interrupting processing?

My situation is:
1) I need to track and handle all key and mouse events
2) I need to perform processing on certain key/mouse events
3) If key/mouse events interrupt processing, the events should not be
discarded since they need to be handled but AFTER the current processing is
complete

Right now, if I press 3 keys really fast and track console messages (to know
what sequence of code executes) I get something like this:
* OnKeyPress(a)
* ProcessingStart(a)
* OnKeyPress(b)
* ProcessingStart(b)
* OnKeyPress(c)
* ProcessingStart(c)
* ProcessingEnd(c)
* ProcessingEnd(b)
* ProcessingEnd(a)

Where this is what I need but don't know how to make happen:
* OnKeyPress(a)
* ProcessingStart(a)
* ProcessingEnd(a)
* OnKeyPress(b)
* ProcessingStart(b)
* ProcessingEnd(b)
* OnKeyPress(c)
* ProcessingStart(c)
* ProcessingEnd(c)

Any help is MUCH appreciated!

Bill
Nov 13 '05 #1
5 3738
On Mon, 7 Jul 2003 22:43:02 -0400, "Bill Henning" <please @
nospamforactiprosoftware.com> wrote:
Does anyone know a good method of preventing keyboard and mouse events from
interrupting processing?


No, but perhaps you should just put the relevant information in a queue and pull
it out with a second thread or upon the occurance of a timer interval.
--
Abderaware
Fine Components For .NET
Turn on, tune in, download.
zane a@t abderaware.com
Nov 13 '05 #2
I think you should solve this with a queue and a boolean.

-- pseudocode --

Queue q
bool isBusy = false;

OnKeyPress(key) {
q.add(key);
// In case nothing is going on
if (!isBusy) ProcessNext();
}

ProcessNext() {
isBusy = true;
while (!q.isEmpty()) {
// Process the top one
}
// Nothing more in the queue, make sure
// that on the following keypress ProcessNext()
// will be called again
isBusy = false;
}

-- end pseudocode --

HTH

Yves

"Bill Henning" <please @ nospamforactiprosoftware.com> schreef in bericht
news:#i**************@TK2MSFTNGP10.phx.gbl...
Does anyone know a good method of preventing keyboard and mouse events from interrupting processing?

My situation is:
1) I need to track and handle all key and mouse events
2) I need to perform processing on certain key/mouse events
3) If key/mouse events interrupt processing, the events should not be
discarded since they need to be handled but AFTER the current processing is complete

Right now, if I press 3 keys really fast and track console messages (to know what sequence of code executes) I get something like this:
* OnKeyPress(a)
* ProcessingStart(a)
* OnKeyPress(b)
* ProcessingStart(b)
* OnKeyPress(c)
* ProcessingStart(c)
* ProcessingEnd(c)
* ProcessingEnd(b)
* ProcessingEnd(a)

Where this is what I need but don't know how to make happen:
* OnKeyPress(a)
* ProcessingStart(a)
* ProcessingEnd(a)
* OnKeyPress(b)
* ProcessingStart(b)
* ProcessingEnd(b)
* OnKeyPress(c)
* ProcessingStart(c)
* ProcessingEnd(c)

Any help is MUCH appreciated!

Bill

Nov 13 '05 #3
Thanks for replying Zane and Yves. The queue idea is probably what I'm
going to have to do.

It would be nice if there was some way in .NET to make that processing into
a critical section to prevent this from happening however since it's all the
same thread, that's not possible I guess.

Thanks again,
Bill

"phoenix" <pa******@skynetWORK.be> wrote in message
news:O9**************@TK2MSFTNGP10.phx.gbl...
I think you should solve this with a queue and a boolean.

-- pseudocode --

Queue q
bool isBusy = false;

OnKeyPress(key) {
q.add(key);
// In case nothing is going on
if (!isBusy) ProcessNext();
}

ProcessNext() {
isBusy = true;
while (!q.isEmpty()) {
// Process the top one
}
// Nothing more in the queue, make sure
// that on the following keypress ProcessNext()
// will be called again
isBusy = false;
}

-- end pseudocode --

HTH

Yves

"Bill Henning" <please @ nospamforactiprosoftware.com> schreef in bericht
news:#i**************@TK2MSFTNGP10.phx.gbl...
Does anyone know a good method of preventing keyboard and mouse events

from
interrupting processing?

My situation is:
1) I need to track and handle all key and mouse events
2) I need to perform processing on certain key/mouse events
3) If key/mouse events interrupt processing, the events should not be
discarded since they need to be handled but AFTER the current processing

is
complete

Right now, if I press 3 keys really fast and track console messages (to

know
what sequence of code executes) I get something like this:
* OnKeyPress(a)
* ProcessingStart(a)
* OnKeyPress(b)
* ProcessingStart(b)
* OnKeyPress(c)
* ProcessingStart(c)
* ProcessingEnd(c)
* ProcessingEnd(b)
* ProcessingEnd(a)

Where this is what I need but don't know how to make happen:
* OnKeyPress(a)
* ProcessingStart(a)
* ProcessingEnd(a)
* OnKeyPress(b)
* ProcessingStart(b)
* ProcessingEnd(b)
* OnKeyPress(c)
* ProcessingStart(c)
* ProcessingEnd(c)

Any help is MUCH appreciated!

Bill


Nov 13 '05 #4
Hi Bill,

Maybe i don't understand your problem?
If i run form in [STAThread] mode, my events are fired in
queue as they were started.

Try this code (after placing ListBox control on your form):

private void LongTimeNothing() {
int i,j,k;
int maxVal=400;
for(i=0; i<maxVal; i++) {
for(j=0; j<maxVal; j++) {
for(k=0; k<maxVal; k++) {
int val=i+j+k;
}
}
}
}

private void listBox1_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs ea) {
listBox1.Items.Add(String.Format("KeyPress for \'{0}\'", ea.KeyChar));
this.LongTimeNothing();
listBox1.Items.Add(String.Format("KeyPress for \'{0}\'", ea.KeyChar));
}

private void listBox1_MouseDown(object sender, System.Windows.Forms.MouseEventArgs ea) {
listBox1.Items.Add(String.Format("MouseDown for \'{0}\'", ea.Button));
this.LongTimeNothing();
listBox1.Items.Add(String.Format("MouseDown for \'{0}\'", ea.Button));
}

....then set listBox1 events for "KeyPress" & "MouseDown" to
proper methods in code

Regards

Marcin Grzębski

Bill Henning wrote:
Does anyone know a good method of preventing keyboard and mouse events from
interrupting processing?

My situation is:
1) I need to track and handle all key and mouse events
2) I need to perform processing on certain key/mouse events
3) If key/mouse events interrupt processing, the events should not be
discarded since they need to be handled but AFTER the current processing is
complete

Right now, if I press 3 keys really fast and track console messages (to know
what sequence of code executes) I get something like this:
* OnKeyPress(a)
* ProcessingStart(a)
* OnKeyPress(b)
* ProcessingStart(b)
* OnKeyPress(c)
* ProcessingStart(c)
* ProcessingEnd(c)
* ProcessingEnd(b)
* ProcessingEnd(a)

Where this is what I need but don't know how to make happen:
* OnKeyPress(a)
* ProcessingStart(a)
* ProcessingEnd(a)
* OnKeyPress(b)
* ProcessingStart(b)
* ProcessingEnd(b)
* OnKeyPress(c)
* ProcessingStart(c)
* ProcessingEnd(c)

Any help is MUCH appreciated!

Bill


Nov 13 '05 #5
Marcin,

I think you're right... I looked over my huge amount of processing code and
found an Application.DoEvents(). When I took that out, it started working
again sequentially as it should. I've learned my lesson with not to use the
DoEvents! :)

Thanks,
Bill
"Marcin Grzębski" <mg*******@stop.spam.taxussi.com.pl> wrote in message
news:be**********@nemesis.news.tpi.pl...
Hi Bill,

Maybe i don't understand your problem?
If i run form in [STAThread] mode, my events are fired in
queue as they were started.

Try this code (after placing ListBox control on your form):

private void LongTimeNothing() {
int i,j,k;
int maxVal=400;
for(i=0; i<maxVal; i++) {
for(j=0; j<maxVal; j++) {
for(k=0; k<maxVal; k++) {
int val=i+j+k;
}
}
}
}

private void listBox1_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs ea) { listBox1.Items.Add(String.Format("KeyPress for \'{0}\'", ea.KeyChar)); this.LongTimeNothing();
listBox1.Items.Add(String.Format("KeyPress for \'{0}\'", ea.KeyChar)); }

private void listBox1_MouseDown(object sender, System.Windows.Forms.MouseEventArgs ea) { listBox1.Items.Add(String.Format("MouseDown for \'{0}\'", ea.Button)); this.LongTimeNothing();
listBox1.Items.Add(String.Format("MouseDown for \'{0}\'", ea.Button)); }

...then set listBox1 events for "KeyPress" & "MouseDown" to
proper methods in code

Regards

Marcin Grzębski

Bill Henning wrote:
Does anyone know a good method of preventing keyboard and mouse events from interrupting processing?

My situation is:
1) I need to track and handle all key and mouse events
2) I need to perform processing on certain key/mouse events
3) If key/mouse events interrupt processing, the events should not be
discarded since they need to be handled but AFTER the current processing is complete

Right now, if I press 3 keys really fast and track console messages (to know what sequence of code executes) I get something like this:
* OnKeyPress(a)
* ProcessingStart(a)
* OnKeyPress(b)
* ProcessingStart(b)
* OnKeyPress(c)
* ProcessingStart(c)
* ProcessingEnd(c)
* ProcessingEnd(b)
* ProcessingEnd(a)

Where this is what I need but don't know how to make happen:
* OnKeyPress(a)
* ProcessingStart(a)
* ProcessingEnd(a)
* OnKeyPress(b)
* ProcessingStart(b)
* ProcessingEnd(b)
* OnKeyPress(c)
* ProcessingStart(c)
* ProcessingEnd(c)

Any help is MUCH appreciated!

Bill

Nov 13 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: John Champaign | last post by:
Hi all, I'm working on an educational applet for a child with special needs. He's got a bit of a trick to make my life more difficult... To interact with the applet he needs to click on...
10
by: Danny | last post by:
How can I get the coordinates of the mouse cursor in Mozilla browsers as well as Opera and IE6? I'm struggling to understand how to capture mouse movement events with Mozilla/Netscape/Firefox and...
3
by: red | last post by:
mouse events when the mouse is on a "child control" hi everyone; my problem: I have a userControl in this usercontrol, I have a child control (a button) when the mouse moves over the...
2
by: KarenP | last post by:
In my Windows Forms application, while executing a process that takes some time, I am changing the cursor to the hourglass by setting Cursor.Current = Cursors.WaitCursor. This is working just...
5
by: Bill Henning | last post by:
Does anyone know a good method of preventing keyboard and mouse events from interrupting processing? My situation is: 1) I need to track and handle all key and mouse events 2) I need to perform...
0
by: Dave | last post by:
Hello, I am writing an On-screen keyboard, similar to the one included in windows 2k and XP. The problem I am having is that I need my keyboard to never get the focus, but still be able to...
3
by: Dave | last post by:
Hi, I have a control on my vb app form that dont cath a mouse event`s how can i catch a mouse event on that control and pass it to a function in my main form??? In VB-6 i used the setcapture api...
8
by: Mike | last post by:
Hi all, I have a DataGridViewCheckBoxColumn as one of my columns in a DataGridView. I want this checkbox to only be checked, but not unchecked - it's used by the user to audit that they have...
0
by: Gamey | last post by:
I have an application that NEEDS (don't ask) to handle additional mouse and keyboard processing during DoDragDrop. Normally, DoDragDrop kindly squashes all keyboard and mouse events. Alternate,...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.