I dont really understand the problem...
but you would need to use the OS api or a custom function.
On Windows you could for example subclass the window or directly listen to the window key messages via PeekMessage_().
Iirc. you can also obtain those messages through Wait/WindowEvent() but it is not officially supported.
Then there is GetKeyboardState_() which gives you the complete state of the keyboard, map the key you are interested in an see if its pressed or not.
The example you posted with the console would also work with KeyboardPushed() because you already know what key you want to time.
Inkey() and KeyboardInkey()
Re: Inkey() and KeyboardInkey()
Thank you Mijikai for all this information...
It's just that I don't understand why KeyboardInkey() waits for the key to be released to return the value while Inkey() returns the value immediately whether the key is released or not...
It's just that I don't understand why KeyboardInkey() waits for the key to be released to return the value while Inkey() returns the value immediately whether the key is released or not...
Re: Inkey() and KeyboardInkey()
Well, it doesn't actually... run the below code and you can see the program changing the text color rapidly, and when you press Esc you get a debug output of the keys that were held down, showing them multiple times while they were held down.
So the program flow continues regardless of using KeyboardInkey(), as you can see by the color still toggling while a key is being held down.
Code: Select all
If InitSprite() And InitKeyboard() And OpenScreen(800,600,32,"")
Repeat
FlipBuffers()
ClearScreen(RGB(100,100,100))
ExamineKeyboard()
resultat$ + KeyboardInkey()
Debug resultat$
If StartDrawing(ScreenOutput())
DrawingMode(1)
t=1-t
If t=0
c=#Red
Else
c=#Green
EndIf
FrontColor(c)
DrawText(20, 20, resultat$)
StopDrawing()
EndIf
Until KeyboardPushed(#PB_Key_Escape)
EndIf
Re: Inkey() and KeyboardInkey()
Hello BarryG,
I tested the program and I don't see what you are saying...
In this small program, the debug window only appears when I release the a key
Try and keep your finger pressed for a few seconds. The debug window will only appear when you release your finger... That's my question.
I tested the program and I don't see what you are saying...
In this small program, the debug window only appears when I release the a key
Try and keep your finger pressed for a few seconds. The debug window will only appear when you release your finger... That's my question.
Code: Select all
If InitSprite() And InitKeyboard() And OpenScreen(800,600,32,"")
Repeat
FlipBuffers()
ClearScreen(RGB(100,100,100))
ExamineKeyboard()
resultat$ + KeyboardInkey()
If resultat$="a"
Debug ("OK")
EndIf
Until KeyboardPushed(#PB_Key_Escape)
EndIf
Re: Inkey() and KeyboardInkey()
Either wait for the mapping KeyInput() facilitates or query the keys states directly.
In order to directly see if a char is pressed you need to map the char to a key scan code.
In order to directly see if a char is pressed you need to map the char to a key scan code.
Re: Inkey() and KeyboardInkey()
My original question was why is there a difference between Inkey() and keyboardInkey()
In the first case, the result is displayed even if the finger is pressed.
In the second case, the result is only displayed WHEN THE finger is removed from the key.
It was just that.
In the first case, the result is displayed even if the finger is pressed.
In the second case, the result is only displayed WHEN THE finger is removed from the key.
It was just that.
- netmaestro
- PureBasic Bullfrog
- Posts: 8433
- Joined: Wed Jul 06, 2005 5:42 am
- Location: Fort Nelson, BC, Canada
Re: Inkey() and KeyboardInkey()
You are mixing apples and oranges here. InKey() is a command you use in a console and it takes a keypress in. KeyboardInKey() is used after InitKeyboard(), ExamineKeyboard(), and KeyboardPushed() (or -released()) with a screen or windowed screen open. With a game I expect that's the one you want. However, they do not work the same. InKey() in a console takes a keypress in. KeyboardInKey() in a screen does not take a keypress in. All it does is remember the last key pressed. Use KeyboardPushed() or KeyboardReleased() to get the character in. Then you can use the KeyboardInKey() command to see what it was and then use it in some way. But remember this, calling it empties it out so you must assign it to a string variable. The help topic for KeyBoardInKey() has example code which shows this quite clearly. Check it out. It should clear up any confusion.
Edit: It occurs to me that a better name for KeyboardInKey() might be KeyboardLastKey(), it's more descriptive of what it does. Just an idea.
Edit: It occurs to me that a better name for KeyboardInKey() might be KeyboardLastKey(), it's more descriptive of what it does. Just an idea.
BERESHEIT
Re: Inkey() and KeyboardInkey()
Hello netmaster,
Thank you for your answer.
Thank you for your answer.