Get keyboard press key

Just starting out? Need help? Post your questions and find answers here.
Wolf
Enthusiast
Enthusiast
Posts: 232
Joined: Sat Apr 03, 2004 12:00 pm
Location: S.T

Get keyboard press key

Post by Wolf »

Hi

How can i get one key when user press that in keyboard ?
LarsG
Enthusiast
Enthusiast
Posts: 713
Joined: Mon Jun 02, 2003 1:06 pm
Location: Norway
Contact:

Post by LarsG »

ExamineKeyboard()
Result = KeyboardPushed(KeyID)

AMD Athlon XP2400, 512 MB RAM, Hercules 3D Prophet 9600 256MB RAM, WinXP
PIII 800MHz, 320 MB RAM, Nvidia Riva Tnt 2 Mach 64 (32MB), WinXP + Linux
17" iMac, 1.8 GHz G5, 512 MB DDR-RAM, 80 GB HD, 64 MB Geforce FX 5200, SuperDrive, OSX
Sunny
User
User
Posts: 16
Joined: Wed Feb 04, 2004 7:46 pm
Location: Germany | Hannover

Post by Sunny »

To check one special key, use this commands:

Code: Select all

initkeyboard()

;inits and co.

;start-mainloop

examinekeyboard()
if keyboardpushed(#PB_Key_Space)
  ;do this, after key-space was pushed
endif

;end-mainloop

Kale
PureBasic Expert
PureBasic Expert
Posts: 3000
Joined: Fri Apr 25, 2003 6:03 pm
Location: Lincoln, UK
Contact:

Post by Kale »

Sunny wrote:To check one special key, use this commands:

Code: Select all

initkeyboard()
;inits and co.
;start-mainloop
examinekeyboard()
if keyboardpushed(#PB_Key_Space)
  ;do this, after key-space was pushed
endif
;end-mainloop
Remember when you use the above InitKeyboard(), ExamineKeyboard(), etc.. DirectX v7+ must be installed! You can use the Win32 API to avoid the need of having DX installed. See: viewtopic.php?t=9437 I think there was a native command added in v3.90 to do this, check the history.txt file and Reference.
--Kale

Image
Wolf
Enthusiast
Enthusiast
Posts: 232
Joined: Sat Apr 03, 2004 12:00 pm
Location: S.T

Post by Wolf »

Thanks LarsG, Sunny and Kale .

But if i use of :

ExamineKeyboard()
Result = KeyboardPushed(KeyID)

It's fast do and end my prog. must use it with loop commands ?

I want if user press one button and hold i can count that character !

How can do this ?
LarsG
Enthusiast
Enthusiast
Posts: 713
Joined: Mon Jun 02, 2003 1:06 pm
Location: Norway
Contact:

Post by LarsG »

you would probably have to use somethign like this:

Code: Select all

a.l = 0
Repeat

  ExamineKeyboard()
  If KeyboardPushed(#PB_KEY_SPACE)
    a +1
  EndIf
Until KeyboardPushed(#PB_KEY_ESCAPE)
note: I don't think this will only work if you open a (windowed)screen..

AMD Athlon XP2400, 512 MB RAM, Hercules 3D Prophet 9600 256MB RAM, WinXP
PIII 800MHz, 320 MB RAM, Nvidia Riva Tnt 2 Mach 64 (32MB), WinXP + Linux
17" iMac, 1.8 GHz G5, 512 MB DDR-RAM, 80 GB HD, 64 MB Geforce FX 5200, SuperDrive, OSX
Wolf
Enthusiast
Enthusiast
Posts: 232
Joined: Sat Apr 03, 2004 12:00 pm
Location: S.T

Post by Wolf »

Thanks LarsG.

I must realy use it with one window ? my prog not have the window :(
LarsG
Enthusiast
Enthusiast
Posts: 713
Joined: Mon Jun 02, 2003 1:06 pm
Location: Norway
Contact:

Post by LarsG »

then you can do a search on this forum for an api call byt the name of GetASyncState or GetASyncKey or something like that.. someone else may ellaborate on this some more..

AMD Athlon XP2400, 512 MB RAM, Hercules 3D Prophet 9600 256MB RAM, WinXP
PIII 800MHz, 320 MB RAM, Nvidia Riva Tnt 2 Mach 64 (32MB), WinXP + Linux
17" iMac, 1.8 GHz G5, 512 MB DDR-RAM, 80 GB HD, 64 MB Geforce FX 5200, SuperDrive, OSX
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Post by PB »

> do a search on this forum for [...] GetASyncState

See here: viewtopic.php?t=8366
Post Reply