473,473 Members | 2,092 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

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 3745
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: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.