November 30, 2020, 02:02:45 AM

Author Topic: [bb] Input "field" by Yahfree [ 1+ years ago ]  (Read 562 times)

Offline BlitzBot

  • Jr. Member
  • **
  • Posts: 1
[bb] Input "field" by Yahfree [ 1+ years ago ]
« on: June 29, 2017, 12:28:41 AM »
Title : Input "field"
Author : Yahfree
Posted : 1+ years ago

Description : This is a basic input field function, Credits to B23 for the "iGetKey()" function and the "InitGetkey()" function.

put all 3 of these functions with the data and types in a include file before the program

to use this, Call the "InitGetKey()" before the main loop and then set up a veriable to get fed info from the "CreateInputBox()" function

the Arguments of the CreateInputBox() function are the following

YourString=CreateInputBox(Box_X, Box_Y, Box_Width, Useable/true/false?, YourString)

Heres a demo:


Code :
Code: BlitzBasic
  1. ;-----------------------------------------------------------------------------------------------------
  2. ;                                                                                          Types
  3. ;-----------------------------------------------------------------------------------------------------
  4.        
  5. ;Type To hold scancodes
  6. Type ScanCode
  7.         Field code
  8.         Field key$
  9.         Field upkey$
  10. End Type
  11.  
  12. ;-----------------------------------------------------------------------------------------------------
  13. ;                                                                                       InitGetKey()
  14. ;-----------------------------------------------------------------------------------------------------
  15. ;reads all scancodes into ScanCode type
  16. Function InitGetKey()
  17.  
  18.  
  19.         ;read scancodes
  20.         tel = 1
  21.         Restore scancodez
  22.         Repeat
  23.                 Read scanc
  24.                 If scanc = -1 Then Exit
  25.                 s.ScanCode = New ScanCode
  26.                 scode = scanc
  27.                 skey$ = Lower$(Mid$("1234567890-=QWERTYUIOP[]ASDFGHJKL;'XCVBNM,./* 789-456+1230.,/", tel, 1))
  28.                 supkey$ = Mid$("!@#$%^&*()_+QWERTYUIOP{}ASDFGHJKL:" + Chr$(34) + "|ZXCVBNM<>?* 789-456+1230.,/", tel, 1)
  29.                 tel = tel + 1
  30.         Forever
  31.  
  32. End Function
  33.  
  34. Global oldkdown
  35. ;-----------------------------------------------------------------------------------------------------
  36. ;                                                                                       iGetKey()
  37. ;-----------------------------------------------------------------------------------------------------
  38. ;imitates GetKey() using scancodes
  39. Function iGetKey()
  40.  
  41.         ;backspace
  42.         If KeyDown(14) Then
  43.                 If oldkdown <> 8 Then oldkdown = 8: Return 8
  44.                 oldkdown = 8: Return
  45.         End If
  46.  
  47.         ;enter
  48.         If KeyDown(28) Or KeyDown(156) Then
  49.                 If oldkdown <> 13 Then oldkdown = 13: Return 13
  50.                 oldkdown = 13: Return
  51.         End If
  52.        
  53.         ;check what key is down
  54.         sel.ScanCode = Null
  55.         down = -1
  56.         For s.ScanCode = Each ScanCode
  57.                 If KeyDown(scode) Then down = scode: sel = s: Exit
  58.         Next
  59.         If down = oldkdown Then Return
  60.         oldkdown = down
  61.  
  62.         ;if no valid key is selected, exit     
  63.         If sel = Null Then Return 0
  64.  
  65.         ;shift for uppercase   
  66.         If KeyDown(42) Or KeyDown(54) Then
  67.                 sc$ = selupkey$
  68.         Else
  69.                 sc$ = selkey$
  70.         End If
  71.  
  72.         ;return ascii value of key     
  73.         Return Asc(sc$)
  74.  
  75. End Function
  76.  
  77.  
  78. ;-------------------------------------------------------------------------------------------------------
  79. ;                                          CreateInputBox()
  80. ;-------------------------------------------------------------------------------------------------------
  81.  
  82. Function CreateInputBox$(box_x,box_y,box_w,useable,returnstr$)
  83.        
  84.         Rect box_x, box_y, box_w,20, False
  85.  
  86. If useable=True
  87.    key=iGetKey()
  88.        
  89.    Rect box_x+3+Len(returnstr$)*9,box_y+2,1,17,1
  90.                
  91.        
  92.   If (key=>48 And key=<57) Or (key>=65 And key<=90) Or (key>=97 And key<=122)
  93.      If(Len(returnstr$)<box_w/10)
  94.         returnstr$ = returnstr$ + Chr(key)
  95.                                
  96.                                
  97. End If
  98.   End If
  99.           End If
  100.  
  101.  
  102. If useable=True
  103. If KeyHit(14)
  104.    If Len(returnstr$)>0 returnstr$=Left(returnstr$,Len(returnstr$)-1)
  105. End If
  106. If KeyHit(57)
  107.   returnstr$=returnstr$+" "
  108. End If
  109. End If
  110.  
  111.  
  112.         Text box_x+3,box_y, returnstr$
  113.  
  114.         Return(returnstr$)
  115.        
  116.                
  117. End Function
  118.  
  119.  
  120.  
  121. ;-------------------------------------------------------------------------------------------------------
  122.                                        ;Data stuff
  123. ;-------------------------------------------------------------------------------------------------------
  124. .scancodez
  125. Data 2, 3, 4, 5, 6, 7, 8, 9, 10, 11
  126. Data 12, 13, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25
  127. Data 26, 27, 30, 31, 32, 33, 34, 35, 36, 37, 38
  128. Data 39, 40, 43, 44, 45, 46, 47, 48, 49, 50, 51
  129. Data 52, 53, 55, 57, 71, 72, 73, 74, 75, 76, 77
  130. Data 78, 79, 80, 81, 82, 83, 179, 181, -1
  131.  
  132.  
  133.  
  134. ;-----------------------------------------------------------------------
  135. ;                                       PROGRAM
  136. ;-----------------------------------------------------------------------
  137.  
  138. ;Include "FunctionLibary.bb"
  139.  
  140. Graphics 400,300,16,2
  141. SetBuffer BackBuffer()
  142.  
  143. InitGetKey()
  144.  
  145. mystring$=""
  146. mystring2$=""
  147. mystring3$=""
  148.  
  149. tf=False
  150. tf2=False
  151. tf3=False
  152.  
  153. controller=1
  154.  
  155. While Not KeyHit(1)
  156. Cls
  157.  
  158. ;CreateInputBox(box_x,box_y,box_w,box_h,useable,strng$)
  159. mystring = CreateInputBox(0,0,300,tf,mystring$)
  160. mystring2=CreateInputBox(0,30,300,tf2,mystring2$)
  161. mystring3=CreateInputBox(0,60,300,tf3,mystring3$)
  162.  
  163.  
  164. Select controller
  165. Case 1
  166. tf=True
  167. tf2=False
  168. tf3=False
  169. Case 2
  170. tf2=True
  171. tf3=False
  172. tf=False
  173. Case 3
  174. tf3=True
  175. tf=False
  176. tf2=False
  177. End Select
  178.  
  179.  
  180. If KeyHit(200)
  181. controller = controller + 1
  182. End If
  183.  
  184. If controller > 3  controller=1
  185.  
  186.  
  187.  
  188. Text 0,280,"TF: "+tf
  189. Text 60,280,"TF2: "+tf2
  190. Text 120,280,"TF3: "+tf3
  191.  
  192.  
  193.  
  194. Delay 5
  195. Flip
  196. Wend
  197. End


Comments : none...

 

SimplePortal 2.3.6 © 2008-2014, SimplePortal