Brutus2D
« key.clear »

Welcome Guest. Please Login or Register.
Dec 24, 2009, 10:48am




Brutus2D :: Brutus2D :: Feature Requests :: key.clear
   [Search This Thread][Send Topic To Friend] [Print]
 AuthorTopic: key.clear (Read 54 times)
peter
Full Member
***
member is offline





Joined: Aug 2007
Gender: Male
Posts: 144
 key.clear
« Thread Started on Jan 10, 2009, 9:06am »

Hi Guilect,

i have ascertained that the Keyboard Buffer will not be cleared.
We need a command like KEY.CLEAR.
Would be much easier to write a keyboard handling.
I have spent a lot of time in order to write an acceptable keyboard input.
The Keyboard Buffer is a ring Buffer with Tail and head.
The Buffer is empty, when the tail and the head get the same position.
But I am sure that you know it !

best regards
Link to Post - Back to Top  IP: Logged
Guilect
Administrator
*****
member is offline




[homepage]

Joined: May 2005
Posts: 843
 Re: key.clear
« Reply #1 on Jan 10, 2009, 8:33pm »

Never had any problems with keyboard buffer before...

But, I will look into a key.clear
Link to Post - Back to Top  IP: Logged
peter
Full Member
***
member is offline





Joined: Aug 2007
Gender: Male
Posts: 144
 Re: key.clear
« Reply #2 on Jan 11, 2009, 12:46pm »

Hi Guilect,

if i go to keyboard input and i pressed the Return key.
Then i cannot do a keyboard input, because it is jumps out
of the keyboard input before i type some Names.
The keyboard input uses also a return key for leaving.
Look here:

Option Explicit
Public Count

Sub Main()
Graphics.Initialize 640,480,True,32
Key.Initialize
Mouse.Initialize
Count =0

While True
KeyStart
System.ProcessMessages
iF Key.Pressed(vk_windowX) Then Exit Sub
Wend

Graphics.Terminate
Key.Terminate
Mouse.Terminate
End Sub

Call Main

Sub KeyStart()
'System.Pause 25
iF Key.Pressed(vk_return) Then
Count = Count +1
Graphics.SetTitle("You pressed Return key! " & Count & "x")
End iF
End Sub
Link to Post - Back to Top  IP: Logged
Guilect
Administrator
*****
member is offline




[homepage]

Joined: May 2005
Posts: 843
 Re: key.clear
« Reply #3 on Jan 11, 2009, 5:02pm »

I checked the keyboard buffer and it is fine.
It gets cleared every time you call Key.Pressed(xxxx).

What you are doing is just running a very tight loop and calling the key.pressed routine many times a second. Say 60 times a second. So you see 60 returns.

Assume the return key is being held down:
In your loop you:

call the key.pressed routine
key.pressed returns true and the keyboard buffer is cleared
you increment the count
loop to beginning again at the rate of ~ 60 times a second

When a human presses the return key it is held down for many milliseconds, all this time your very fast loop in incrementing the count.

A very fast update on keys is what is wanted in games. And this is accomplished via the DirectX Direct Input module which the Key object in Brutus2D is using.

To do what you want, there is a simple method :
Code:
Option Explicit
Public Count, returnkeyup

returnkeyup = false

Sub Main()
Graphics.Initialize 640,480,True,32
Key.Initialize
Mouse.Initialize
Count =0

While True
KeyStart
System.ProcessMessages
iF Key.Pressed(vk_windowX) Then Exit Sub
Wend

Graphics.Terminate
Key.Terminate
Mouse.Terminate
End Sub

Call Main

Sub KeyStart()
'System.Pause 25
iF Key.Pressed(vk_return) = false then returnkeyup = true
iF Key.Pressed(vk_return) = true and returnkeyup = true Then
    returnkeyup = false
    Count = Count +1
    Graphics.SetTitle("You pressed Return key! " & Count & "x")
End iF
End Sub
Link to Post - Back to Top  IP: Logged
peter
Full Member
***
member is offline





Joined: Aug 2007
Gender: Male
Posts: 144
 Re: key.clear
« Reply #4 on Jan 11, 2009, 6:16pm »

yes, that also denouement !
I can need it.

apart from that, BlitzMax has a ClearKeys command.
And it work fantastic !

Thank you for your open ear.
For the moment i have nothing to bleat !
Link to Post - Back to Top  IP: Logged
   [Search This Thread][Send Topic To Friend] [Print]

Google
Web brutus2d.proboards44.com
Click Here To Make This Board Ad-Free


This Board Hosted For FREE By ProBoards
Get Your Own Free Message Boards & Free Forums!