It is currently Fri Jan 22, 2021 5:00 am

All times are UTC + 1 hour




Post new topic Reply to topic  [ 3 posts ] 
Author Message
 Post subject: SpiderBasic Keyboard/Mouse values
PostPosted: Sun Nov 03, 2019 4:52 am 
Offline
New User
New User

Joined: Sun Sep 15, 2019 1:37 am
Posts: 2
Hi guys, New to SpiderBasic. It's a bit of a learning curve for me.

For some reason, I can't get input from the Keyboard or Mouse in my program. The two sample programs that demonstrate Keyboard and Mouse control use their input to move a sprite on the screen. I'm not using sprites. I just want to capture Keyboard and/or Mouse input to trigger my app. But for the life of me, I can't get them working...

I'm calling "InitMouse", and yet "ExamineMouse()" is never true.

When I called "InitKeyboard", "ExamineKeyboard()" is never true. (You'll see it's currently commented out)

It's got to be something simple, yet I'm not seeing it. I've tried dozens of combinations of moving the Init up top, etc, to no avail.

And I'm an 'old-school' 80's/90's BASIC guy, so I'm not used to all the setup of the 'drawing surface', etc. So my code is nowhere near optimized or as 'clean' as it could/should be... Have mercy on my 51-year-old brain, LOL...

Here's (most of) my code -- the only thing I cut out was my working logic to draw my clock and timer on the screen...
Code:
EnableExplicit

Global SizeX=3840
Global SizeY=2160
Global ASizeX,MX=0
Global ASizeY,MY=0
Global GXOffset=200
Global Prev_TMSECS,TMSECS=0 
Global TimerSecs=1*60; Default 20 mins
Global TimerEnd=Date()+(TimerSecs);
Global TMHHMMSS$,HROD$,HRTXT$,HRTD$,HR$,HRAP$,PrevTS$=""
Global KBKEY$=""
Global KBKEY.i=0
Global SID,HRINT,ID,zz=0
Global TimerHR,TimerMN,TimerSE
Global TimerMN$,TimerSE$
Global TimerColor
Global TimerRunning=#False
Global TimerMsg$=""
Global XScale.f=1.0
Global YScale.f=1.0
Global Top,GadgetHeight,k=0
Global Result$=""
Global WheelDelta=0;
;--------------------------------------------------------------------------------------------------------

Procedure ProcessKeys()
  Debug "ProcessKeys called..."
  If ExamineMouse()
    MX = MouseX()
    MY = MouseY()
    If MouseButton(#PB_MouseButton_Left)
      Debug "Left button "+MX+","+MY
      TimerSecs=TimerSecs+60
    EndIf
   
    If MouseButton(#PB_MouseButton_Right)
      Debug "Right button "+MX+","+MY
      TimerSecs=TimerSecs+60
    EndIf
   
    If MouseButton(#PB_MouseButton_Middle)
      Debug "Middle button "+MX+","+MY
    EndIf
   
    WheelDelta = MouseWheel()
    If WheelDelta
      Debug "Mouse wheel: " + WheelDelta+" "+MX+","+MY
    EndIf
  EndIf
   
  If ExamineKeyboard()
    KBKEY$=KeyboardInkey()
    Debug "Key "+KBKEY$+" pressed..."
    If KeyboardPushed(#PB_Key_S)
      TimerRunning=Abs(TimerRunning-1)
    EndIf
    If KeyboardPushed(#PB_Key_A)
      TimerSecs=TimerSecs+60
    ElseIf KeyboardPushed(#PB_Key_Z)
      TimerSecs=TimerSecs-60
      If (TimerSecs<0)
        TimerSecs=0
      EndIf
    EndIf
  EndIf
EndProcedure


Procedure DrawTime(XOffset,YOffset,HRTD$,HROD$,MINS$,SECS$,HRAP$,TMColor,DrawSmallSemi)
  XOffset=Int(XOffset*XScale)
  YOffset=Int(YOffset*XScale)
  DrawingFont(FontID(0))
  FrontColor(TMColor)
  ; Draw Hours (space insted of '0' for first char)
  DrawText(XOffset,YOffset,HRTD$)
  DrawText(XOffset+Int(273*XScale),YOffset,HROD$)
  If (Val(HRTD$)*10+Val(HROD$)>0)
    ; Draw HH:MM Colon
    DrawText(XOffset+Int(450*XScale),YOffset,":")
  EndIf
  ; Draw Minutes (Always 2 digits)
  DrawText(XOffset+Int(630*XScale),YOffset,MINS$)
 
  ; Draw Seconds
  DrawingFont(FontID(1))
 
  If (DrawSmallSemi > 0)
    ; Semicolon near seconds...
    DrawText(XOffset+Int(1130*XScale),YOffset+Int(240*XScale),":")   
  EndIf
  ; Draw Seconds
  DrawText(XOffset+Int(1230*XScale),YOffset+Int(240*XScale),SECS$)
 
  ; Draw AM/PM
  DrawingFont(FontID(2))
  If (HRAP$="AM")       
    DrawText(XOffset,YOffset+Int(134*XScale),HRAP$)
  ElseIf (HRAP$="PM")
    DrawText(XOffset,YOffset+Int(308*XScale),HRAP$)
  ElseIf (HRAP$<>"")
    If (HRAP$ = "OVER")
      DrawingMode(#PB_2DDrawing_Outlined)
      RoundBox(XOffset+Int(1212*XScale),YOffset+Int(120*XScale),Int(304*XScale),Int(140*XScale),20,20,RGB(255,255,0))
      FrontColor(RGB(255,255,0))
      DrawingMode(#PB_2DDrawing_Transparent)
      DrawText(XOffset+Int(1228*XScale),YOffset+Int(116*XScale),HRAP$)
      DrawingMode(#PB_2DDrawing_Default)
      FrontColor(TMColor)
    Else
      DrawText(XOffset+Int(20*XScale),YOffset+Int(220*XScale),HRAP$)
    EndIf
  EndIf
EndProcedure

Procedure DrawScreen(ScrnNum)
 
  ; Get window size with a little help from JavaScript (to auto-scale my display)...
  EnableJS
  v_asizex = window.innerWidth;
  v_asizey = window.innerHeight;
  DisableJS
  XScale=ASizeX/1920
  YScale=ASizeY/1080
  ;Debug "Window Size="+Str(ASizeX)+","+Str(ASizeY)+"   Scale="+Str(XScale*1000)+","+Str(XScale*1000)
 
  If CreateImage(ScrnNum, ASizeX, ASizeY)
    If StartDrawing(ImageOutput(ScrnNum))
      DrawingMode(#PB_2DDrawing_Transparent)
      BackColor(RGB(160,160,160)) ; Change the text back and front colour
     
      LoadFont(0, "Digital-7 Mono", Int(600*XScale))
      LoadFont(1, "Digital-7 Mono", Int(300*XScale))
      LoadFont(2, "Digital-7 Mono", Int(150*XScale))
      LoadFont(3, "Digital-7 Mono", Int(80*XScale))

      === working code to draw my clock and timer... ===
     
      StopDrawing()
      ; Create a gadget to display our image
     
      ImageGadget(ScrnNum, 0, 0, SizeX, SizeY, ImageID(ScrnNum))
      FlipBuffers();    ;### DOESN'T CHANGE IF I HAVE THIS COMMENTED OUT OR NOT...
    EndIf
  EndIf
EndProcedure

Procedure ProcessTimer()
  DrawScreen(0)
EndProcedure

;If InitKeyboard() And OpenWindow(0, 0, 0, SizeX, SizeY, "FFC Timer", #PB_Window_BorderLess)
If InitMouse(#PB_Mouse_Locked) And OpenWindow(0, 0, 0, SizeX, SizeY, "FFC Timer", #PB_Window_BorderLess)
  AddWindowTimer(0,0,200)                           # THIS WORKS
  BindEvent(#PB_Event_Timer, @ProcessTimer())       # THIS WORKS
  BindEvent(#PB_Event_LeftClick, @ProcessKeys())    # APPEARS TO DO NOTHING
EndIf


Top
 Profile  
Reply with quote  
 Post subject: Re: SpiderBasic Keyboard/Mouse values
PostPosted: Sun Nov 03, 2019 6:20 am 
Offline
Addict
Addict

Joined: Thu Apr 18, 2019 8:17 am
Posts: 1199
jartz wrote:
Hi guys, New to SpiderBasic.

Hi! The forum you want is here: https://forums.spiderbasic.com/index.php


Top
 Profile  
Reply with quote  
 Post subject: Re: SpiderBasic Keyboard/Mouse values
PostPosted: Tue Nov 05, 2019 3:35 am 
Offline
New User
New User

Joined: Sun Sep 15, 2019 1:37 am
Posts: 2
Thanks BarryG, I didn't realize there was a separate forum...

Jeff


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 4 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye