DzikoSoft Excel Gaming Forum
September 06, 2010, 11:20:00 PM
Welcome,
Guest
. Please
login
or
register
.
1 Hour
1 Day
1 Week
1 Month
Forever
Login with username, password and session length
News
: Excel Games Library now lists over 150 games!
Home
Help
Login
Register
DzikoSoft Excel Gaming Forum
>
Excel Gaming
>
Developers' Lair
(Moderators:
Clut
,
Thargoid
) >
Keyboard Buffer
Pages: [
1
]
« previous
next »
Print
Author
Topic: Keyboard Buffer (Read 123 times)
Thargoid
Moderator
Gender:
Posts: 48
Keyboard Buffer
«
on:
July 07, 2010, 04:45:04 AM »
Does anyone know how to clear the keyboard buffer so that code doesn't try to execute twice?
I've searched online but it seems to be one of those things that's just impossible.
Logged
Ched80
Spellcaster
Gender:
Posts: 67
Re: Keyboard Buffer
«
Reply #1 on:
July 07, 2010, 06:17:05 AM »
hey,
Not sure how to clear the keyboard buffer, but I had an issue with a macro that kept executing multiple times. I solved the problem by using a flag in a cell. If the flag was 0 the sub would continue and set the flag to 1. The flag was reset using another sub at a later time. It doesn't solve the problem directly, but the work around helped me.
Logged
Clut
Moderator
Posts: 131
Creator of simpleRPG
Re: Keyboard Buffer
«
Reply #2 on:
July 07, 2010, 11:45:23 AM »
I have used the same solution as Ched has used.
use a cell somewhere to act as a flag, or status that indicates whether or not somthing is already being processed.
The key is remebering to set the flag when your code starts processing anything, and to clear the flag when your code has finished.
If new code tries to start executing while the flag is set, just exit sub it.
Logged
Faz
Apprentice
Posts: 45
Re: Keyboard Buffer
«
Reply #3 on:
July 07, 2010, 04:53:39 PM »
Yep, that's the easiest way i think.
It's like what you should when you add code to the worksheet selection change event. If that code involves selecting other cells then the event will try to run again and again and again, unless you do that and have a variable in there that disables the event to be run again.
Logged
Thargoid
Moderator
Gender:
Posts: 48
Re: Keyboard Buffer
«
Reply #4 on:
July 08, 2010, 02:41:54 AM »
Excellent - some good ideas - I'll try them out.
I'm trying to drop out of the macro in XLite's docked screens, but it keeps flashing up to say that the sheet's protected if I press "A" (autopilot) multiple times.
Just getting rid of that annoying message box would be good.
Logged
Thargoid
Moderator
Gender:
Posts: 48
Re: Keyboard Buffer
«
Reply #5 on:
July 09, 2010, 04:18:34 PM »
I solved the problem of the irritating message box.
In the end it's a simple and obvious solution.
As soon as the key (key A) is pressed in the GetASyncKeyState loop, use Application.Onkey to point key A at a macro that doesn't do anything.
When the original macro has finished executing, the remaining A's come barrelling into view only to trigger a case of nothing happening.
...
...
Would a key pointing to such a macro still trigger the KeyState event?
I'm going to have to check that now.
Logged
Faz
Apprentice
Posts: 45
Re: Keyboard Buffer
«
Reply #6 on:
July 11, 2010, 05:09:06 AM »
Whenever i use the GetAsyncKeyState function in a constant loop (to check for button presses) if i only want one trigger to occur for each button press, what i do is have a variable in there, perhaps a global variable, to be boolean. For example if the Z key did something like shoot it would be like this...
Private zReleased As Boolean
Private Function checkKeys()
{
If GetAsyncKeyState(vbKeyZ) Then
If zReleased Then
Call shootOnce
zReleased = False
End If
Else
zReleased = True
End If
}
Logged
Pages: [
1
]
Print
« previous
next »
Jump to:
Please select a destination:
-----------------------------
Excel Gaming
-----------------------------
=> Excel Games - General
=> Developers' Lair
=> Project RPG.XLS: The Buried Curse
-----------------------------
Off -topic
-----------------------------
=> Coffee Break
Loading...