Getting ASCII Code of pressed key

Just starting out? Need help? Post your questions and find answers here.
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post 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)
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post 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
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post 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)
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by Danilo.

And look at #WM_CHAR too...
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post 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
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post 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
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post 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
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post 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
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post 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
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post 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
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post 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)
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post 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
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post 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)
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post 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
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post 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.
Post Reply