none
Holding left/right mouse down to continue a routine RRS feed

  • Question

  • I want to hold left/right mouse down and have numbers increase or decrease in button caption or text box.  I can do it with single clicks but holding mouse down defeats me.  Any ideas?

    'try to scroll numbers in button caption or textbox

    xp=200
    yp=200

    box1=Controls.addbutton(3,xp,yp)
    GraphicsWindow.DrawText(xp+50, yp, box1)

    box2=controls.AddTextBox(xp,yp+100)
    Controls.SetTextBoxText(box2,5)
    GraphicsWindow.DrawText(xp+50,yp+100,box2)
    Controls.SetSize(box2,30,20)

    Controls.buttonclicked=doitbutton
    GraphicsWindow.MouseDown=onmousedown
    Controls.texttyped=doittext
    n=1
    '=======================================

    Sub doitbutton
      If Controls.LastClickedButton=box1 Then
        Controls.setbuttoncaption(box1,n)
        Controls.SetTextBoxText(box2,n)
      EndIf  
    endsub

    Sub doittext
      ' TextWindow.WriteLine("text")
      If Controls.lasttypedtextbox=box2 then
        Controls.setbuttoncaption(box1,n)
        Controls.SetTextBoxText(box2,n)
        Program.Delay(300)
      endif
    EndSub

    Sub onmousedown
      
      domore:
      if (Mouse.IsLeftButtonDown) then
        n=n+1
        Controls.setbuttoncaption(box1,n)
        Controls.SetTextBoxText(box2,n)
        Program.Delay(200)
      Endif
      
      If (Mouse.isleftbuttondown) Then 
        TextWindow.WriteLine("mouse "+n)
      endif
      
      while (Mouse.IsRightButtonDown) 
        n=n-1
        TextWindow.WriteLine("rght down "+n)
        Controls.setbuttoncaption(box1,n)
        Controls.SetTextBoxText(box2,n)
        Program.Delay(200)
      endwhile 
      
    endsub


    Saturday, August 29, 2015 4:54 AM

Answers

All replies

  • Please wait. Now I see it...
    Saturday, August 29, 2015 9:44 AM
  • (translated by Google translator)

    Your code has a lot of bugs. But...

    Here's your code that does it for the left button:

    xp=200
    yp=200
    
    box1=Controls.addbutton(3,xp,yp)
    GraphicsWindow.DrawText(xp+50, yp, box1)
    
    box2=controls.AddTextBox(xp,yp+100)
    Controls.SetTextBoxText(box2,5)
    GraphicsWindow.DrawText(xp+50,yp+100,box2)
    Controls.SetSize(box2,30,20)
    
    Controls.buttonclicked=doitbutton
    GraphicsWindow.MouseDown=onmousedown
    GraphicsWindow.MouseUp = onMouseUp
    Controls.texttyped=doittext
    n=1
    
    '-----------    new code
    var_OnMouseDown = "false"
    
    Point1:
    If var_OnMouseDown = "true" Then
      n=n+1
      Controls.setbuttoncaption(box1,n)
      Controls.SetTextBoxText(box2,n)
    
    EndIf
    
    Program.Delay(1000)
    Goto Point1
    
    '=======================================
    
    Sub doitbutton
      If Controls.LastClickedButton=box1 Then
        Controls.setbuttoncaption(box1,n)
        Controls.SetTextBoxText(box2,n)
      EndIf  
    endsub
    
    Sub doittext
      ' TextWindow.WriteLine("text")
      If Controls.lasttypedtextbox=box2 then
        Controls.setbuttoncaption(box1,n)
        Controls.SetTextBoxText(box2,n)
        Program.Delay(300)
      endif
    EndSub
    
    Sub onmousedown
      var_OnMouseDown = "true"
      
      while (Mouse.IsRightButtonDown) 
        n=n-1
        TextWindow.WriteLine("rght down "+n)
        Controls.setbuttoncaption(box1,n)
        Controls.SetTextBoxText(box2,n)
        Program.Delay(200)
      endwhile 
      
    endsub
    
    
    Sub onMouseUp
      var_OnMouseDown = "false"
      
    EndSub


    Saturday, August 29, 2015 10:17 AM
  • WOW!!  Many thanks!  Woke up this AM to present under the tree :-).    A little subtlety in the sb language.

    deuce336

    Saturday, August 29, 2015 2:10 PM
  • Um... one small detail.  When the delay is lowered to 200 or so, smooth number change is lost... and it jumps.  I have experienced this with my other attempts.  Any ideas?

    deuce336

    Saturday, August 29, 2015 2:54 PM
  • (translated by Google translator)

    I'm sorry, but your code has a lot of errors. For your program can worked well you must write a completely new code.

    Saturday, August 29, 2015 3:35 PM
  • To keep the count up smooth you can rely on the Clock object.

    Here's a rewrite using Shapes like a button. I've used LDShapes.Width/height to help update ShapeSize.

    PVF410-0

    Tuesday, September 1, 2015 7:41 AM
    Moderator
  • I just put Controls.SetSize after Shapes.SetText and that fixed my issue with Zooming X-axis.

    PVF410-1

    Tuesday, September 1, 2015 8:03 AM
    Moderator
  • I seem to be missing something... no code shown... does not appear to be a propos of my situation.

    deuce336

    Tuesday, September 1, 2015 3:06 PM
  • duece

    Here's the program ID: PVF410-3

    Click the Import button in small basic and paste it in.

    You'll need the LD extension as well to run it,

    Tuesday, September 1, 2015 4:30 PM
    Moderator
  • Thanks JJ...  I was sort of obtuse... still a newbie.  

    deuce336

    Tuesday, September 1, 2015 7:19 PM
  • No worries deuce

    Sorry I used an extension, you may not be using them yet. I had no choice though, I needed to get the width/height of the button as it changed size.

    btw in the last sample I ditched the zoom feature about the x-axis because it wasn't working the way I expected. The solution still looks like a button press though.

    The main points are I used the Clock object to increase the counting up (1,2,3....) not Program.delay.

    I used the Program.delay in a main loop to give the loop a small break otherwise the loop runs flat out infinitely. That's a lot of work for your cpu.

    Tuesday, September 1, 2015 11:43 PM
    Moderator
  • Here is the simplest way:

    While 1 = 1 
      Program.Delay(10)
      If Mouse.IsLeftButtonDown Then
        Num = Num + 1
      EndIf
      If Mouse.IsRightButtonDown Then
        Num = Num - 1
      EndIf
      TextWindow.Clear()
      TextWindow.WriteLine(Num)
      EndWhile

    Hope that helps!


    It is written: "'As surely as I live,' says the Lord, 'every knee will bow before me; every tongue will acknowledge God.'" Romans 14:11

    Thursday, September 3, 2015 3:38 PM
    Answerer
  • Many thanks to all who have replied...  Below the progress I have made.  But still some problems.

    The program scrolls numbers on each button.  However the start is not "elegant". 

    The mouse right button down functions while the cursor is on the button.  But the left button down does not.  Left and right button down functions anywhere on screen...although working only on the selected button.

     I would like the left/right button down to function only while cursor is on the button. 

    Interesting observation ...  "true" "false" are case independent... but other strings are not.

    Here my puny efforts...

    xp=200
    yp=200

    n=3
    box1=Controls.addbutton(n,xp,yp)
    GraphicsWindow.DrawText(xp+50, yp, box1)

    yp=yp+50
    box2=Controls.addbutton(n,xp,yp)
    GraphicsWindow.DrawText(xp+50, yp, box2)

    yp=yp+100
    boxdoit=Controls.addbutton("Doit",xp,yp)

    Controls.buttonclicked=onbuttonclicked
    GraphicsWindow.MouseDown=onmousedown
    GraphicsWindow.MouseUp = onMouseUp

    var_OnMouseDown = "false"
    vonbuttonclicked="false"
    vdoit="true"

    While vdoit="true"
      If vonbuttonclicked ="true" Then
        'Assign n to whatever button has been pressed
        If Controls.lastclickedbutton=box1 then
          n=Controls.GetButtonCaption(box1)
        endif
       
        If Controls.lastclickedbutton=box2 then
          n=controls.GetButtonCaption(box2)
        endif
       
        If var_OnMouseDown = "True" Then
          If Mouse.isleftbuttondown="true" then
            n=n+1
          endif
          If Mouse.isrightbuttondown="True" then
            n=n-1
          endif
         
          'Show number for whatever button has been clicked
          If Controls.lastclickedbutton=box1 then
            Controls.setbuttoncaption(box1,n)
          endif
         
          If Controls.lastclickedbutton=box2 then
            Controls.setbuttoncaption(box2,n)
          endif
        EndIf
       
       Program.Delay(200)
       
      EndIf 
    endwhile

    results=controls.GetButtonCaption(box1) + ",  " +controls.GetButtonCaption(box2)
    GraphicsWindow.DrawText(xp+100,yp,"Done it:   "+results)

    '=======================================
    Sub onbuttonclicked
      If Controls.lastclickedbutton=boxdoit Then
        vdoit="false"
      endif
     
      vonbuttonclicked="true"
    endsub 

    Sub onmousedown
      var_OnMouseDown = "true"
    endsub


    Sub onMouseUp
      var_OnMouseDown = "false"
    EndSub

     


    deuce336

    Friday, September 4, 2015 3:53 AM
  • Ok. Sorry for over complicating this.

    Here's my solution using only buttons and Mouse.IsLeftButtonDown Or Mouse.IsRightButtonDown

    Import: FVV519

    Saturday, September 5, 2015 1:18 AM
    Moderator
  • GASP!! JJ, clean and elegant.   I cannot thank you too much.  I had no idea that shapes had that potential.  This has been inspirational in continuing sb education.  Btw, the reason I wanted this number scroll is because I am amusing myself by trying to write a program to record blood pressure, pulse, weight, temperature and any other diurnal record.  The scroll box is the method of data entry...

    Many thanks again.

    Now...if only I could kill or at least push to the side intellisense...

    \\//


    deuce336

    Saturday, September 5, 2015 2:48 AM
  • No worries.

    I should've done it that way 1st up.

    You can squeeze intellisense all the way out by dragging its border.

    Saturday, September 5, 2015 3:12 AM
    Moderator
  • The stuff on right is just fine... it is the damn box that pops up as I am writing code...

    deuce336

    Saturday, September 5, 2015 2:10 PM
  • It is strange that we need to go through contortions to do what is standard: i.e., choose an item from a list... such as a date, age, state name...etc. 

    Maybe I stated the problem incorrectly.  What I am trying to do is select a number (or text)  from a list.  This sets parameters for processing.

    Putting the entire page under a "while" loop seems to be inelegant.

    \\//


    deuce336

    Saturday, September 5, 2015 2:35 PM