Page 1 of 2

Posted: Mon Jun 24, 2002 2:08 pm
by BackupUser
Restored from previous forum. Originally posted by merendo.

How do I find out the ASCII Code of a key, which the user has pressed? Please don´t tell me, that I have to use Inkey() 'cos this command needs a console opened first and I don´t want to open one.

Can you help me? Does your solution also tell me, if there is a key pressed (How to find out the ASCII Code of a pressed key, if there is no key pressed)

Thanks for any help, merendo

We always need to hear both sides of the story (by Phil Collins)

Posted: Mon Jun 24, 2002 2:49 pm
by BackupUser
Restored from previous forum. Originally posted by El_Choni.

I remember doing it by processing the #WM_KEYDOWN message, but I can't help you further since I don't have the source here, sorry.

Bye,

El_Choni

Posted: Mon Jun 24, 2002 6:39 pm
by BackupUser
Restored from previous forum. Originally posted by merendo.

Thanks anyway. I will experiment with #WM_KEYDOWN a little bit.

merendo

We always need to hear both sides of the story (by Phil Collins)

Posted: Mon Jun 24, 2002 6:48 pm
by BackupUser
Restored from previous forum. Originally posted by Danilo.

And look at #WM_CHAR too...

Posted: Tue Jun 25, 2002 3:32 am
by BackupUser
Restored from previous forum. Originally posted by PB.

> How do I find out the ASCII Code of a key, which the user has pressed?

Not sure yet, but I may come up with an answer later when I have time.

>Can you [...] tell me, if there is a key pressed

You can use the following to check the state of any key:

Code: Select all

InitKeyboard() ; Must be called before checking keys.
Repeat
  sleep_(1) ; To stop using 100% of CPU.
  ExamineKeyboard() ; Check status of all keys.
  If KeyboardPushed(#PB_Key_All)0 : Debug "Keys are being pressed" : EndIf
  If KeyboardPushed(#PB_Key_Space)0 : Debug "The Spacebar is being pressed" : EndIf
Until KeyboardPushed(#PB_Key_Escape)0 ; Quit if Esc is pressed.

PB - Registered PureBasic Coder

Posted: Tue Jun 25, 2002 7:46 am
by BackupUser
Restored from previous forum. Originally posted by fred.

These commands use DirectX and are for game only ! AddKeyboardShortcut() is the clean way to do it. Or check the #WM_CHAR event.

Fred - AlphaSND

Posted: Tue Jun 25, 2002 10:15 am
by BackupUser
Restored from previous forum. Originally posted by PB.

> These commands use DirectX and are for game only !

Well, the docs say "should be used only for games or applications which need
a raw and extremly fast keyboard access", so how was I supposed to know?

PB - Registered PureBasic Coder

Posted: Tue Jun 25, 2002 5:07 pm
by BackupUser
Restored from previous forum. Originally posted by tranquil.

repeat

delay(1)
until a=0


will never be a good solution for applications. Please wait for events, everytime! That would be the best way for fast appz with less CPU time.

Mike

Tranquilizer/ Secretly!
Registred PureBasic User

Posted: Tue Jun 25, 2002 9:58 pm
by BackupUser
Restored from previous forum. Originally posted by PB.

> Please wait for events, everytime!

It was just for that example because the example had no window...


PB - Registered PureBasic Coder

Posted: Wed Jun 26, 2002 8:58 am
by BackupUser
Restored from previous forum. Originally posted by tranquil.
> Please wait for events, everytime!

It was just for that example because the example had no window...


PB - Registered PureBasic Coder
In fact, catching events withour a window is very hard. :)))))

Mike

Tranquilizer/ Secretly!
Registred PureBasic User

Posted: Fri Jun 28, 2002 9:25 pm
by BackupUser
Restored from previous forum. Originally posted by merendo.

Yes. It is VERY hard to catch events without a window :wink:))) .

No, seriously: I don't want to open a window, I need the ascii code finder for a game which me and a few friends of mine are coding. I want to create a text input for the game and need to find out the ascii code of the key which the user has pressed.

Cu @ll, merendo

We always need to hear both sides of the story (by Phil Collins)

Posted: Fri Jun 28, 2002 9:43 pm
by BackupUser
Restored from previous forum. Originally posted by PB.

> need to find out the ascii code of the key which the user has pressed.

What type of ASCII codes? All keys? Just letters of the alphabet? I need to
know in case it makes it easier for me to do it...


PB - Registered PureBasic Coder

Posted: Fri Jun 28, 2002 9:48 pm
by BackupUser
Restored from previous forum. Originally posted by merendo.

In Case??? I don't know what you mean. I just want to find out the ascii codes, nothing more and nothing less. ASCII Code, I think you know what this is: 78 is M . I want to use the Asc command to create an input field in my game.

We always need to hear both sides of the story (by Phil Collins)

Posted: Sat Jun 29, 2002 11:16 am
by BackupUser
Restored from previous forum. Originally posted by PB.

> I just want to find out the ascii codes, nothing more and nothing less.

Try my new GetKey() procedure here: http://tinyurl.com/il2


PB - Registered PureBasic Coder

Edited by - PB on 29 June 2002 12:18:59

Posted: Sat Jun 29, 2002 8:49 pm
by BackupUser
Restored from previous forum. Originally posted by merendo.

Thank you @all, but especially @ PB. Your code works. May I use it for a game?

merendo

Cu @ll, merendo
--
Go as far as you can, and realize at last, that you are there again, where you have started your way.