Help with CONSOLE (Input instruction)

Post your coding questions such as 'how to' here.
Post Reply
Chopepo
Newcomer
Posts: 4
Joined: Mon Aug 03, 2009 3:58 am

Help with CONSOLE (Input instruction)

Post by Chopepo » Thu Aug 25, 2011 4:43 am

Hi

I have a problem and need help ... please:)

I'm doing a program on CB, and drew a keyboard on the screen. In another part of the screen is a console (use "Input ()" instrucction).

The keyboard is numeric and has numbers 0 through 9 ... The idea is that clicking on the numbers of this keyboard to write the characters on the console.

That's my problem ... I can write to the console using the keyboard of my computer, but I want to write to this console using the keyboard that drew on the screen.

someone can put a source code example ???.... Thanks in advance.

Greetings. Bye.

TheFish
Developer
Developer
Posts: 477
Joined: Mon Aug 27, 2007 9:28 pm
Location: Joensuu

Re: Help with CONSOLE (Input instruction)

Post by TheFish » Thu Aug 25, 2011 7:14 am

Chopepo wrote:Hi

I have a problem and need help ... please:)

I'm doing a program on CB, and drew a keyboard on the screen. In another part of the screen is a console (use "Input ()" instrucction).

The keyboard is numeric and has numbers 0 through 9 ... The idea is that clicking on the numbers of this keyboard to write the characters on the console.

That's my problem ... I can write to the console using the keyboard of my computer, but I want to write to this console using the keyboard that drew on the screen.

someone can put a source code example ???.... Thanks in advance.

Greetings. Bye.
You don't need input for that. Just make a string variable, to which you can append the numbers when you click the buttons.

pseudocode example:

Code: Select all

str = ""
repeat
   write str on screen

  if mouseclick then
    if mouse over a button
       append the number of the clicked button to str
    endif
  endif
forever
CoolBasic henkilökuntaa
Kehittäjä

chopepox

Re: Help with CONSOLE (Input instruction)

Post by chopepox » Thu Aug 25, 2011 9:23 pm

Hello:) Thanks for responding:

But I do not understand your answer. Look:

I need to do a calculator. Then, I have a numeric keypad screen, and above the keyboard is a text box to insert the numbers. I need you to click on the keypad numbers, these numbers are written in the text box.

User avatar
Latexi95
Guru
Posts: 1163
Joined: Sat Sep 20, 2008 5:10 pm
Location: Lempäälä

Re: Help with CONSOLE (Input instruction)

Post by Latexi95 » Thu Aug 25, 2011 10:23 pm

chopepox wrote:Hello:) Thanks for responding:

But I do not understand your answer. Look:

I need to do a calculator. Then, I have a numeric keypad screen, and above the keyboard is a text box to insert the numbers. I need you to click on the keypad numbers, these numbers are written in the text box.
You mean something like this?

Code: Select all

inputstr$ = ""

Repeat
    Color 255,255,255
    Text 10,10,"Text:"+inputstr
    
    
    
    x = 10
    y = 50
    For i = 0 To 9
        addtostr = False
        
        //Draw button and check if it's down
        If KeyButton(i+48,x,y,20,20) Then addtostr = True
        
        //Check key inputs
        If i = 0 Then
            If KeyHit(11) Then addtostr = True
        Else
            If KeyHit(i+1) Then addtostr = True
        EndIf
        
        //If button was pressed or key was hit then add number to string
        If addtostr Then
            inputstr$ = inputstr$ + i
        EndIf
        
        //Next coordinates....
        x + 30
        If x > 200 Then x = 10:y = y + 30
    Next i
    
    //Backspace
    If KeyButton(60,x,y,20,20) Or KeyHit(14) Then
        If Len(Inputstr$) > 0 Then
            inputstr$ = Left(inputstr$,Len(inputstr$)-1)
        EndIf
    EndIf
    

DrawScreen
Forever



Function KeyButton(keycode,x,y,w,h)
    If MouseX() > x And MouseX() < x+w And MouseY()>y And MouseY()<y+h Then
        //If mouse over button

        If MouseDown(1) Then
            //If mouse button down
            Color 150,150,150
            Box x,y,w,h
            Color 0,0,0
            Text x+w/2-4,y+h/2-5,Chr(keycode)
            Return False
        ElseIf MouseUp(1)
            //Mouse button released
            Color 160,160,160
            Box x,y,w,h
            Color 0,0,0
            Text x+w/2-4,y+h/2-5,Chr(keycode)
            Return True
        Else
            Color 185,185,185
            Box x,y,w,h
            Color 0,0,0
            Text x+w/2-4,y+h/2-5,Chr(keycode)
            Return False
        EndIf
    EndIf
    Color 200,200,200
    Box x,y,w,h
    Color 0,0,0
    Text x+w/2-4,y+h/2-5,Chr(keycode)
    Return False
EndFunction

chopepos

Re: Help with CONSOLE (Input instruction)

Post by chopepos » Fri Aug 26, 2011 2:39 am

Yes!!! all right!! is exactly what I wanted!! thanks! and excuse my bad English but I speak Spanish. xD.

Your program worked for me perfect:) Thank you.

Greetings.

Post Reply

Who is online

Users browsing this forum: No registered users and 3 guests