Qbasicnews.com
December 12, 2018, 09:58:50 AM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News: Back to Qbasicnews.com | QB Online Help | FAQ | Chat | All Basic Code | QB Knowledge Base
 
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: Freebasic and CHR$(0) + Arrows Keys Key Codes  (Read 12626 times)
Clay Dragon
Member
*
Posts: 38


WWW
« on: April 13, 2007, 10:24:13 PM »

Greetings everyone, I'm trying to port my QBasic RPG Engine to FreeBasic and the following code does not work, the arrows keys are not responding:

Code:
SELECT CASE kbd$
   CASE CHR$(0) + "H"
    CALL MoveUp
    WorldData.Action = True
   CASE CHR$(0) + "P"
    CALL MoveDown
    WorldData.Action = True
   CASE CHR$(0) + "K"
    CALL MoveLeft
    WorldData.Action = True
   CASE CHR$(0) + "M"
    CALL MoveRight
    WorldData.Action = True
   CASE CHR$(27)
    END
  END SELECT


So, is there a way to work with arrows keys in FreeBasic?

Thanks!
Logged
RayBritton
New Member

Posts: 24


« Reply #1 on: April 14, 2007, 04:35:41 AM »

Yes, in freebasic its Chr(255) instead of chr(0)

heres every key I could think of:
Code:

dim shared as string upkey,downkey,leftkey,rightkey,pageupkey,pagedownkey,homekey
dim shared as string endkey,inskey,delkey,enterkey,tabkey,esckey,exitkey
dim shared as string stabkey,supkey,sdownkey,sleftkey,srightkey
dim shared as string chomekey,cendkey,cprtsckey,cupkey,cdownkey,cleftkey,crightkey,cpageupkey,cpagedownkey,centerkey,ctabkey
dim shared as string F1,F2,F3,f4,f5,f6,f7,f8,f9,f10,f11,f12
dim shared as string sF1,sF2,sF3,sf4,sf5,sf6,sf7,sf8,sf9,sf10,sf11,sf12
dim shared as string cF1,cF2,cF3,cf4,cf5,cf6,cf7,cf8,cf9,cf10,cf11,cf12
dim shared as string aF1,aF2,aF3,af4,af5,af6,af7,af8,af9,af10,af11,af12
dim shared as string aa,ab,ac,ad,ae,af,ag,ah,ai,aj,ak,al,am,an,ao,ap,aq,ar,a_s,at,au,av,aw,ax,ay,az
dim shared as string a1,a2,a3,a4,a5,a6,a7,a8,a9,a0
dim shared as string aequalskey,ahyphenkey,aupkey,adownkey,aleftkey,arightkey
UpKey = CHR$(255) + CHR$(72)
DownKey = CHR$(255) + CHR$(80)
LeftKey = CHR$(255) + CHR$(75)
RightKey = CHR$(255) + CHR$(77)
PageUpkey = CHR$(255) + CHR$(73)
PageDownkey = CHR$(255) + CHR$(81)
HomeKey = CHR$(255) + CHR$(71)
EndKey = CHR$(255) + CHR$(79)
InsKey = CHR$(255) + CHR$(82)
DelKey = CHR$(255) + CHR$(83)
EnterKey = CHR$(13)
TabKey = CHR$(9)
Esckey = CHR$(27)
exitbutton=chr$(255)+"k"  'the X button in the corner of the window
sTabkey = chr$(255) + CHR$(15)
cHomekey = chr$(255) + CHR$(119)
cEndkey = chr$(255) + CHR$(117)
cPrtSckey = chr$(255) + CHR$(114)
cUpKey = chr$(255) + CHR$(141)
cDownKey = chr$(255) + CHR$(145)
cLeftKey = chr$(255) + CHR$(115)
cRightKey = chr$(255) + CHR$(116)
cPageDownkey = chr$(255) + CHR$(118)
cPageUpkey = chr$(255) + CHR$(132)
cTabkey = chr$(255) + CHR$(148)
cEnterkey = chr$(255) + CHR$(10)
F1 = chr$(255) + CHR$(59)
F2 = chr$(255) + CHR$(60)
F3 = chr$(255) + CHR$(61)
F4 = chr$(255) + CHR$(62)
F5 = chr$(255) + CHR$(63)
F6= chr$(255) + CHR$(64)
F7 = chr$(255) + CHR$(65)
F8 = chr$(255) + CHR$(66)
F9 = chr$(255) + CHR$(67)
F10 = chr$(255) + CHR$(68)
F11 = chr$(255) + CHR$(133)
F12 = chr$(255) + CHR$(134)
sF1 = chr$(255) + CHR$(84)
sF2 = chr$(255) + CHR$(85)
sF3 = chr$(255) + CHR$(86)
sF4 = chr$(255) + CHR$(87)
sF5 = chr$(255) + CHR$(88)
sF6 = chr$(255) + CHR$(89)
sF7 = chr$(255) + CHR$(90)
sF8 = chr$(255) + CHR$(91)
sF9 = chr$(255) + CHR$(92)
sF10 = chr$(255) + CHR$(93)
sF11 = chr$(255) + CHR$(135)
sF12 = chr$(255) + CHR$(136)
cF1 = chr$(255) + CHR$(94)
cF2 = chr$(255) + CHR$(95)
cF3 = chr$(255) + CHR$(96)
cF4 = chr$(255) + CHR$(97)
cF5 = chr$(255) + CHR$(98)
cF6 = chr$(255) + CHR$(99)
cF7 = chr$(255) + CHR$(100)
cF8 = chr$(255) + CHR$(101)
cF9 = chr$(255) + CHR$(102)
cF10 = chr$(255) + CHR$(103)
cF11 = chr$(255) + CHR$(137)
cF12 = chr$(255) + CHR$(138)
aF1 = chr$(255) + CHR$(104)
aF2 = chr$(255) + CHR$(105)    
aF3 = chr$(255) + CHR$(106)
aF4 = chr$(255) + CHR$(107)
    aF5 = chr$(255) + CHR$(108)
    aF6 = chr$(255) + CHR$(109)
    aF7 = chr$(255) + CHR$(110)
    aF8 = chr$(255) + CHR$(111)
    aF9 = chr$(255) + CHR$(112)
    aF10 = chr$(255) + CHR$(113)
    aF11 = chr$(255) + CHR$(139)
    aF12 = chr$(255) + CHR$(140)
    a1 = chr$(255) + CHR$(120)
    a2 = chr$(255) + CHR$(121)
    a3 = chr$(255) + CHR$(122)
    a4 = chr$(255) + CHR$(123)
    a5 = chr$(255) + CHR$(124)
    a6 = chr$(255) + CHR$(125)
    a7 = chr$(255) + CHR$(126)
    a8 = chr$(255) + CHR$(127)
    a9 = chr$(255) + CHR$(128)
    a0 = chr$(255) + CHR$(129)
    aHyphenkey = chr$(255) + CHR$(130)
    aequalskey = chr$(255) + CHR$(131)
    aUpkey = chr$(255) + CHR$(152)
    aDownkey = chr$(255) + CHR$(160)
    aLeftkey = chr$(255) + CHR$(155)
    aRightkey = chr$(255) + CHR$(157)
    aQ= chr$(255) + CHR$(16)
    aW= chr$(255) + CHR$(17)
    aE= chr$(255) + CHR$(18)
    aR= chr$(255) + CHR$(19)
    aT= chr$(255) + CHR$(20)
    aY= chr$(255) + CHR$(21)
    aU= chr$(255) + CHR$(22)
    aI= chr$(255) + CHR$(23)
    aO= chr$(255) + CHR$(24)
    aP= chr$(255) + CHR$(25)
    aA= chr$(255) + CHR$(30)
    a_S= chr$(255) + CHR$(31)
    aD= chr$(255) + CHR$(32)
    aF= chr$(255) + CHR$(33)
    aG= chr$(255) + CHR$(34)
    aH= chr$(255) + CHR$(35)
    aJ= chr$(255) + CHR$(36)
    aK= chr$(255) + CHR$(37)
    aL= chr$(255) + CHR$(38)
    aZ= chr$(255) + CHR$(44)
    aX= chr$(255) + CHR$(45)
    aC= chr$(255) + CHR$(46)
    aV= chr$(255) + CHR$(47)
    aB= chr$(255) + CHR$(48)
    aN= chr$(255) + CHR$(49)
    aM= chr$(255) + CHR$(50)


btw, this is a modified version of a qb file
Logged
Clay Dragon
Member
*
Posts: 38


WWW
« Reply #2 on: April 14, 2007, 11:50:24 AM »

Thanks a lot!!! Cheesy
Logged
Anonymous
Guest
« Reply #3 on: April 14, 2007, 07:21:59 PM »

Also consider using Multikey, it's the FreeBASIC evrsion of old Milo's multikey we all loved in QB.

http://www.freebasic.net/wiki/wikka.php?wakka=keypgmultikey

#include "fbgfx.bi"

and then you have the keycodes defined Wink Check FreeBASIC/inc/fbgfx.bi for some other constants defined for you.
Logged
Clay Dragon
Member
*
Posts: 38


WWW
« Reply #4 on: April 14, 2007, 08:22:30 PM »

Thank you Chaos for your input!

But it's a shame I never heard of Multikey before! Please tell me more about it. Is it faster or take less memory than CHR$(255) + "Insert Character here"? If not, why did people love it in QB?
Logged
Zack
*/-\*
*****
Posts: 3974



WWW
« Reply #5 on: April 14, 2007, 10:13:56 PM »

The main benefit is that it allows multiple keypresses, where INKEY only allows one at a time.
Logged

f only life let you press CTRL-Z.
--------------------------------------
Freebasic is like QB, except it doesn't suck.
Clay Dragon
Member
*
Posts: 38


WWW
« Reply #6 on: April 15, 2007, 02:39:59 PM »

Thank you Zack! It is definitely a good benefit indeed! Cheesy
Logged
Anonymous
Guest
« Reply #7 on: April 16, 2007, 01:00:36 AM »

The reason people didn't use it in QB as much is because it wasn't included in QB.

Inkey is good for like, typing in a line, multikey is better for real-time input handling, like using an arrow key to move a character.

Multikey is faster, because inkey uses strings, which does introduce some overhead. Multikey is integer codes.

Also, multiple keypresses are somewhat limited, due to standard keyboard drivers, you usually can't hold more than 3 keys down before new ones simply won't register. Not a FB bug, a keyboard driver limitation.
Logged
Clay Dragon
Member
*
Posts: 38


WWW
« Reply #8 on: April 16, 2007, 07:30:27 PM »

Thank you Chaos!

I will definitely use MultiKey in my RPG Engine!
Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.21 | SMF © 2015, Simple Machines Valid XHTML 1.0! Valid CSS!