Register | Login
Views: 19364387
Main | Memberlist | Active users | ACS | Commons | Calendar | Online users
Ranks | FAQ | Color Chart | Photo album | IRC Chat
11-02-05 12:59 PM
0 user currently in Programming. | 3 guests
Acmlm's Board - I2 Archive - Programming - WM_KEYDOWN Issue | |
Add to favorites | "RSS" Feed | Next newer thread | Next older thread
User Post
beneficii

Lakitu
Level: 36

Posts: 430/567
EXP: 299656
For next: 8454

Since: 06-27-04
From: Cordova, TN, USA

Since last post: 14 hours
Last activity: 6 hours
Posted on 08-27-05 10:01 PM Link | Quote
I have an issue when the user holds down a key for too long. When pipes are loaded in my SMB3 Map Editor, you can switch between various pipe sets with the page up and page down keys (which are read through the WM_KEYDOWN message). When you press one of them, it unloads the old pipe set and loads the new one and draws it to the screen. Unfortunately, if the user tries to go through the pipe sets by holding page up/down, then the program will freeze. My guess is that the window is receiving the keyboard input that is too fast for it to handle, and so it locks up. Is there a way of slowing down this input for the window when the user holds it down (without making the user go to the control panel to slow it down and without changing it for the whole system) or is there some other way around this?

Thanks.

UPDATE: I tried putting them under WM_KEYUP, but doing it too fast still causes it to freeze up.


(edited by beneficii on 08-27-05 01:30 PM)
(edited by beneficii on 08-27-05 01:35 PM)
Dish

Spiny
Level: 38

Posts: 538/596
EXP: 355646
For next: 14801

Since: 03-15-04
From: Disch

Since last post: 18 days
Last activity: 18 days
Posted on 08-27-05 11:19 PM Link | Quote
the WM_KEYDOWN repeat rate is one of the user preferences set in Windows (the speed can be changed in one of the control panels), so no, you're program can't (or at least shouldn't) try to change the speed at which WM_KEYDOWN messages are sent.

The obvious solution here sounds to me like you should just not process WM_KEYDOWN messages if your program is too far behind. This could be done by doing some checks in your message pump:




MSG msg;
int ok_to_sleep;
while( program_open )
{
  ok_to_sleep = 1;
  while( PeekMessage( your_wnd, &msg, 0, 0, PM_REMOVE) )
  {
    TranslateMessage(&msg);
    DispatchMessage(&msg);
    ok_to_sleep = 0;
  }

  program_busy = 0; // queue is clear, program is no longer busy

  if(ok_to_sleep)
    Sleep(1);
}




Then in your ChangePipeSets function or whatever.. just do a check to see if the program is busy before continuing:




void ChangePipeSets()
{
  if(program_busy) return; //abort, program is too busy

  program_busy = 1; //this will make the program busy

  // do the rest of the work here
}


beneficii

Lakitu
Level: 36

Posts: 431/567
EXP: 299656
For next: 8454

Since: 06-27-04
From: Cordova, TN, USA

Since last post: 14 hours
Last activity: 6 hours
Posted on 08-28-05 12:06 AM Link | Quote
Originally posted by Disch
the WM_KEYDOWN repeat rate is one of the user preferences set in Windows (the speed can be changed in one of the control panels), so no, you're program can't (or at least shouldn't) try to change the speed at which WM_KEYDOWN messages are sent.

The obvious solution here sounds to me like you should just not process WM_KEYDOWN messages if your program is too far behind. This could be done by doing some checks in your message pump:




MSG msg;
int ok_to_sleep;
while( program_open )
{
ok_to_sleep = 1;
while( PeekMessage( your_wnd, &msg, 0, 0, PM_REMOVE) )
{
TranslateMessage(&msg);
DispatchMessage(&msg);
ok_to_sleep = 0;
}

program_busy = 0; // queue is clear, program is no longer busy

if(ok_to_sleep)
Sleep(1);
}




Then in your ChangePipeSets function or whatever.. just do a check to see if the program is busy before continuing:




void ChangePipeSets()
{
if(program_busy) return; //abort, program is too busy

program_busy = 1; //this will make the program busy

// do the rest of the work here
}





This seems like quite a thing to implement. Is there any simpler way?
Dish

Spiny
Level: 38

Posts: 539/596
EXP: 355646
For next: 14801

Since: 03-15-04
From: Disch

Since last post: 18 days
Last activity: 18 days
Posted on 08-28-05 12:31 AM Link | Quote
Quite a thing? It's only like 4 lines of code. You already have a message pump, just clear a 'busy' var when there are no messages pending, check the 'busy' var before doing lengthy work, and set the 'busy' var when you start doing lengthy work.

Anyway, there are other ways to do it. All you have to do is figure out a way for your program to tell itself that it's too busy to do the requested workload. Another way to do this would be to flush the message queue after you finish with lengthy work so that any repeat messages are discared ... although this will toss all other messages as well -- such as quit requests and other crap (so I don't recommend it)

Really, this way isn't that hard.


By the way, no need to quote my entire post if you're just replying with a single liner
beneficii

Lakitu
Level: 36

Posts: 432/567
EXP: 299656
For next: 8454

Since: 06-27-04
From: Cordova, TN, USA

Since last post: 14 hours
Last activity: 6 hours
Posted on 08-28-05 08:13 AM Link | Quote
OK, implementing.


(edited by beneficii on 08-27-05 11:13 PM)
Add to favorites | "RSS" Feed | Next newer thread | Next older thread
Acmlm's Board - I2 Archive - Programming - WM_KEYDOWN Issue | |


ABII


AcmlmBoard vl.ol (11-01-05)
© 2000-2005 Acmlm, Emuz, et al



Page rendered in 0.013 seconds.