473,725 Members | 1,967 Online
Bytes | Software Development & Data Engineering Community
+ 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 3762
On Mon, 7 Jul 2003 22:43:02 -0400, "Bill Henning" <please @
nospamforactipr osoftware.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 @ nospamforactipr osoftware.com> schreef in bericht
news:#i******** ******@TK2MSFTN GP10.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******@skyne tWORK.be> wrote in message
news:O9******** ******@TK2MSFTN GP10.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 @ nospamforactipr osoftware.com> schreef in bericht
news:#i******** ******@TK2MSFTN GP10.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_KeyPre ss(object sender, System.Windows. Forms.KeyPressE ventArgs ea) {
listBox1.Items. Add(String.Form at("KeyPress for \'{0}\'", ea.KeyChar));
this.LongTimeNo thing();
listBox1.Items. Add(String.Form at("KeyPress for \'{0}\'", ea.KeyChar));
}

private void listBox1_MouseD own(object sender, System.Windows. Forms.MouseEven tArgs ea) {
listBox1.Items. Add(String.Form at("MouseDown for \'{0}\'", ea.Button));
this.LongTimeNo thing();
listBox1.Items. Add(String.Form at("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.DoE vents(). 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.c om.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_KeyPre ss(object sender, System.Windows. Forms.KeyPressE ventArgs ea) { listBox1.Items. Add(String.Form at("KeyPress for \'{0}\'", ea.KeyChar)); this.LongTimeNo thing();
listBox1.Items. Add(String.Form at("KeyPress for \'{0}\'", ea.KeyChar)); }

private void listBox1_MouseD own(object sender, System.Windows. Forms.MouseEven tArgs ea) { listBox1.Items. Add(String.Form at("MouseDown for \'{0}\'", ea.Button)); this.LongTimeNo thing();
listBox1.Items. Add(String.Form at("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
6225
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 buttons, which is fine most of the time (he comes from a Mac environment, so I accept mouse clicks from the right or left button when he's working on the PC). But every once in a while, he'll press and hold the right mouse button, move onto a JButton,...
10
18077
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 I've Googled so much my brain hurts. http://www.ghpkendal.co.uk/TestPages/Test.htm Move your cursor over the yellow area and you should see the mouse coordinates echoed above.
3
10644
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 userControl, I can detect the movement using MouseMove event. the problem is when the mouse is on the child control : I can t detect
2
10092
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 fine, except that any mouse events generated during this wait period (such as clicking on a button, etc.), get processed once the processing is complete. For example, while waiting for my task to complete, I click on a button (even though the...
5
2024
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 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
0
1098
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 process events such as mouse clicks. I have tried setting focus back to the app that just lost the focus, however in smoe application this does not work as the caret/cursor is
3
3045
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 function! Thanks
8
9227
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 "seen" and checked an order. In VB6 I would handle the Mouse Button Down event, test the target cell and set the mouse event arguements to nothing. This doesn't actually work in ..NET, allowing the user to deselect the checkbox.
0
1610
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, more specific events, are used in their stead such as DragEnter, DragLeave, DragHover, GiveFeedback, and QueryContinueDrag. None of these give me access to the general state of the keyboard or to mouse events ( in my case I really need the mouse...
0
9401
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9257
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9174
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8096
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6702
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6011
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4782
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3221
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2634
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.