SlideShare ist ein Scribd-Unternehmen logo
1 von 8
Microsoft® Small Basic Events and Interactivity Estimated time to complete this lesson: 1 hour
Events and Interactivity In this lesson, you will learn about: Using keyboard events in your program. Using mouse events in your program.
Introduction to Events In other words, you can create an interactive program in Small Basic by defining events that trigger an action in response to user inputs.  This lesson introduces you to events and controls with which you can add interactivity to your Small Basic programs.  Interactivity here also includes control events that trigger an       action on the click of a button or when some text is entered   in a text box.
 Keyboard Events Keyboard events produce an action when a certain key is pressed. There are two keyboard events—KeyDownand KeyUp. These events are defined as operations of the GraphicsWindow object. KeyUp raises an event when a key is released on the keyboard. KeyDown raises an event when a key is pressed down on the keyboard.
Keyboard Events Let’s demonstrate keyboard events in Small Basic with a simple program that allows you to rotate a shape on the graphics window by pressing a key on the keyboard. In this example, you use the Return key on the keyboard to rotate a rectangle shape in the graphics window. When you press the Return key, the rectangle rotates, and on releasing the Return key, the rectangle returns to its original state.
Mouse Events Let’s see how we can use these events in a program. MouseDown raises an event when the mouse button is clicked. MouseUp raises an event when the mouse button is released Like keyboard events, you can create programs in Small Basic that work with events based on mouse clicks. Mouse events generate actions in your program with the click of a mouse. MouseMove raises an event when the mouse is moved around in the graphics window.
Let’s Summarize… Congratulations! Now you know how to: Use keyboard events in your program. Using mouse events in your program.
It’s Time to Apply Your Learning… Write a program to demonstrate the Mouse events by performing the following steps: ,[object Object]

Weitere ähnliche Inhalte

Was ist angesagt?

3.1 file input and output
3.1   file input and output3.1   file input and output
3.1 file input and outputallenbailey
 
Creating a Personalized ipad Wallpaper
Creating a Personalized ipad WallpaperCreating a Personalized ipad Wallpaper
Creating a Personalized ipad Wallpaperszanotti
 
Kendra Cooper's Resizing Images with Smart Art Tutorial
Kendra Cooper's Resizing Images with Smart Art TutorialKendra Cooper's Resizing Images with Smart Art Tutorial
Kendra Cooper's Resizing Images with Smart Art TutorialKendraCooper6
 
Step by Step guide for creating first ABAP report in SAP
Step by Step guide for creating first ABAP report in SAPStep by Step guide for creating first ABAP report in SAP
Step by Step guide for creating first ABAP report in SAPnityaabap
 
Creating a package_in_abap_navigator
Creating a package_in_abap_navigatorCreating a package_in_abap_navigator
Creating a package_in_abap_navigatornityaabap
 
Stepshot Intro
Stepshot IntroStepshot Intro
Stepshot IntroStepShot
 
Google Quick Tip - Spell Check
Google Quick Tip - Spell CheckGoogle Quick Tip - Spell Check
Google Quick Tip - Spell Checkcloudbakers
 
Google I/O 2016 replay - Android N Development
Google I/O 2016 replay - Android N DevelopmentGoogle I/O 2016 replay - Android N Development
Google I/O 2016 replay - Android N DevelopmentTowhidul Haque Roni
 
Ubuntuwindows
UbuntuwindowsUbuntuwindows
Ubuntuwindowsandymafu
 
Tips and tricks for navigating the new windows 8 user interface
Tips and tricks for navigating the new windows 8 user interfaceTips and tricks for navigating the new windows 8 user interface
Tips and tricks for navigating the new windows 8 user interfaceRavi Kumar Lanke
 
Augmented reality session 2
Augmented reality session 2Augmented reality session 2
Augmented reality session 2NirsandhG
 
How to Generate Thumbnail Images in Bulk
How to Generate Thumbnail Images in BulkHow to Generate Thumbnail Images in Bulk
How to Generate Thumbnail Images in Bulkmoshecary04
 
Windows Virtual Keyboard modification
Windows Virtual Keyboard modificationWindows Virtual Keyboard modification
Windows Virtual Keyboard modificationtopomax
 

Was ist angesagt? (20)

3.1 file input and output
3.1   file input and output3.1   file input and output
3.1 file input and output
 
Small basic
Small basicSmall basic
Small basic
 
Creating a Personalized ipad Wallpaper
Creating a Personalized ipad WallpaperCreating a Personalized ipad Wallpaper
Creating a Personalized ipad Wallpaper
 
Kendra Cooper's Resizing Images with Smart Art Tutorial
Kendra Cooper's Resizing Images with Smart Art TutorialKendra Cooper's Resizing Images with Smart Art Tutorial
Kendra Cooper's Resizing Images with Smart Art Tutorial
 
Setting Up A Blog 3
Setting Up A Blog 3Setting Up A Blog 3
Setting Up A Blog 3
 
Step by Step guide for creating first ABAP report in SAP
Step by Step guide for creating first ABAP report in SAPStep by Step guide for creating first ABAP report in SAP
Step by Step guide for creating first ABAP report in SAP
 
Creating a package_in_abap_navigator
Creating a package_in_abap_navigatorCreating a package_in_abap_navigator
Creating a package_in_abap_navigator
 
Stepshot Intro
Stepshot IntroStepshot Intro
Stepshot Intro
 
Google Quick Tip - Spell Check
Google Quick Tip - Spell CheckGoogle Quick Tip - Spell Check
Google Quick Tip - Spell Check
 
812 wordpress tablet
812 wordpress tablet812 wordpress tablet
812 wordpress tablet
 
Google Cloud Print
Google Cloud PrintGoogle Cloud Print
Google Cloud Print
 
Google I/O 2016 replay - Android N Development
Google I/O 2016 replay - Android N DevelopmentGoogle I/O 2016 replay - Android N Development
Google I/O 2016 replay - Android N Development
 
Ubuntuwindows
UbuntuwindowsUbuntuwindows
Ubuntuwindows
 
Tips and tricks for navigating the new windows 8 user interface
Tips and tricks for navigating the new windows 8 user interfaceTips and tricks for navigating the new windows 8 user interface
Tips and tricks for navigating the new windows 8 user interface
 
Windows 7
Windows 7Windows 7
Windows 7
 
Augmented reality session 2
Augmented reality session 2Augmented reality session 2
Augmented reality session 2
 
How to Generate Thumbnail Images in Bulk
How to Generate Thumbnail Images in BulkHow to Generate Thumbnail Images in Bulk
How to Generate Thumbnail Images in Bulk
 
Windows Virtual Keyboard modification
Windows Virtual Keyboard modificationWindows Virtual Keyboard modification
Windows Virtual Keyboard modification
 
Tokbox Training
Tokbox TrainingTokbox Training
Tokbox Training
 
Get Your Grades in Angel
Get Your Grades in AngelGet Your Grades in Angel
Get Your Grades in Angel
 

Ähnlich wie 3.4 events and interactivity

Introduction to GUIs with guizero
Introduction to GUIs with guizeroIntroduction to GUIs with guizero
Introduction to GUIs with guizeroprimeteacher32
 
06 win forms
06 win forms06 win forms
06 win formsmrjw
 
Google calendar integration in iOS app
Google calendar integration in iOS appGoogle calendar integration in iOS app
Google calendar integration in iOS appKetan Raval
 
Software engineering modeling lab lectures
Software engineering modeling lab lecturesSoftware engineering modeling lab lectures
Software engineering modeling lab lecturesmarwaeng
 
3.5 the controls object
3.5   the controls object3.5   the controls object
3.5 the controls objectallenbailey
 
Alice05
Alice05Alice05
Alice05h2vs10
 
Throughout the semester, we have been working on command line applic.pdf
Throughout the semester, we have been working on command line applic.pdfThroughout the semester, we have been working on command line applic.pdf
Throughout the semester, we have been working on command line applic.pdfbirajdar2
 
Synapse india reviews on gui programming in .net
Synapse india reviews on gui programming in .netSynapse india reviews on gui programming in .net
Synapse india reviews on gui programming in .netsaritasingh19866
 
Ch 3 event driven programming
Ch 3 event driven programmingCh 3 event driven programming
Ch 3 event driven programmingChaffey College
 
Gui builder
Gui builderGui builder
Gui builderlearnt
 

Ähnlich wie 3.4 events and interactivity (20)

Introduction to GUIs with guizero
Introduction to GUIs with guizeroIntroduction to GUIs with guizero
Introduction to GUIs with guizero
 
Introduction
IntroductionIntroduction
Introduction
 
9b4c1 vb(pd) (2)
9b4c1 vb(pd) (2)9b4c1 vb(pd) (2)
9b4c1 vb(pd) (2)
 
9b4c1 vb(pd)
9b4c1 vb(pd)9b4c1 vb(pd)
9b4c1 vb(pd)
 
06 win forms
06 win forms06 win forms
06 win forms
 
visual basic programming
visual basic programmingvisual basic programming
visual basic programming
 
Google calendar integration in iOS app
Google calendar integration in iOS appGoogle calendar integration in iOS app
Google calendar integration in iOS app
 
Software engineering modeling lab lectures
Software engineering modeling lab lecturesSoftware engineering modeling lab lectures
Software engineering modeling lab lectures
 
3.5 the controls object
3.5   the controls object3.5   the controls object
3.5 the controls object
 
Ppt lesson 03
Ppt lesson 03Ppt lesson 03
Ppt lesson 03
 
Unit-1.pptx
Unit-1.pptxUnit-1.pptx
Unit-1.pptx
 
Alice05
Alice05Alice05
Alice05
 
Event handling in Java(part 1)
Event handling in Java(part 1)Event handling in Java(part 1)
Event handling in Java(part 1)
 
Throughout the semester, we have been working on command line applic.pdf
Throughout the semester, we have been working on command line applic.pdfThroughout the semester, we have been working on command line applic.pdf
Throughout the semester, we have been working on command line applic.pdf
 
Synapse india reviews on gui programming in .net
Synapse india reviews on gui programming in .netSynapse india reviews on gui programming in .net
Synapse india reviews on gui programming in .net
 
Spf chapter10 events
Spf chapter10 eventsSpf chapter10 events
Spf chapter10 events
 
Ch 3 event driven programming
Ch 3 event driven programmingCh 3 event driven programming
Ch 3 event driven programming
 
Gui builder
Gui builderGui builder
Gui builder
 
A Primavera Tutorial
A Primavera TutorialA Primavera Tutorial
A Primavera Tutorial
 
Vb.net and .Net Framework
Vb.net and .Net FrameworkVb.net and .Net Framework
Vb.net and .Net Framework
 

Mehr von allenbailey

4.4 advanced games
4.4   advanced games4.4   advanced games
4.4 advanced gamesallenbailey
 
4.3 collision detection
4.3   collision detection4.3   collision detection
4.3 collision detectionallenbailey
 
4.2 responding to events
4.2   responding to events4.2   responding to events
4.2 responding to eventsallenbailey
 
4.1 playing with shapes
4.1   playing with shapes4.1   playing with shapes
4.1 playing with shapesallenbailey
 
3.3 the math object
3.3   the math object3.3   the math object
3.3 the math objectallenbailey
 
3.2 stacks and arrays
3.2   stacks and arrays3.2   stacks and arrays
3.2 stacks and arraysallenbailey
 
2.6 flickr, image list, and network objects
2.6   flickr, image list, and network objects2.6   flickr, image list, and network objects
2.6 flickr, image list, and network objectsallenbailey
 
2.5 clock, desktop, and dictionary objects
2.5   clock, desktop, and dictionary objects2.5   clock, desktop, and dictionary objects
2.5 clock, desktop, and dictionary objectsallenbailey
 
2.3 exploring shapes
2.3   exploring shapes2.3   exploring shapes
2.3 exploring shapesallenbailey
 
2.2 turtle graphics
2.2   turtle graphics2.2   turtle graphics
2.2 turtle graphicsallenbailey
 
2.1 graphics window
2.1   graphics window2.1   graphics window
2.1 graphics windowallenbailey
 

Mehr von allenbailey (12)

4.4 advanced games
4.4   advanced games4.4   advanced games
4.4 advanced games
 
4.3 collision detection
4.3   collision detection4.3   collision detection
4.3 collision detection
 
4.2 responding to events
4.2   responding to events4.2   responding to events
4.2 responding to events
 
4.1 playing with shapes
4.1   playing with shapes4.1   playing with shapes
4.1 playing with shapes
 
3.3 the math object
3.3   the math object3.3   the math object
3.3 the math object
 
3.2 stacks and arrays
3.2   stacks and arrays3.2   stacks and arrays
3.2 stacks and arrays
 
2.6 flickr, image list, and network objects
2.6   flickr, image list, and network objects2.6   flickr, image list, and network objects
2.6 flickr, image list, and network objects
 
2.5 clock, desktop, and dictionary objects
2.5   clock, desktop, and dictionary objects2.5   clock, desktop, and dictionary objects
2.5 clock, desktop, and dictionary objects
 
2.3 exploring shapes
2.3   exploring shapes2.3   exploring shapes
2.3 exploring shapes
 
2.2 turtle graphics
2.2   turtle graphics2.2   turtle graphics
2.2 turtle graphics
 
2.1 graphics window
2.1   graphics window2.1   graphics window
2.1 graphics window
 
1.3 variables
1.3   variables1.3   variables
1.3 variables
 

Kürzlich hochgeladen

"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo DayH2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo DaySri Ambati
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionDilum Bandara
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxLoriGlavin3
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsPixlogix Infotech
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfRankYa
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...Fwdays
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024Lonnie McRorey
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piececharlottematthew16
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024Stephanie Beckett
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .Alan Dix
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Enterprise Knowledge
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 

Kürzlich hochgeladen (20)

"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo DayH2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An Introduction
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and Cons
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdf
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piece
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 

3.4 events and interactivity

  • 1. Microsoft® Small Basic Events and Interactivity Estimated time to complete this lesson: 1 hour
  • 2. Events and Interactivity In this lesson, you will learn about: Using keyboard events in your program. Using mouse events in your program.
  • 3. Introduction to Events In other words, you can create an interactive program in Small Basic by defining events that trigger an action in response to user inputs. This lesson introduces you to events and controls with which you can add interactivity to your Small Basic programs. Interactivity here also includes control events that trigger an action on the click of a button or when some text is entered in a text box.
  • 4. Keyboard Events Keyboard events produce an action when a certain key is pressed. There are two keyboard events—KeyDownand KeyUp. These events are defined as operations of the GraphicsWindow object. KeyUp raises an event when a key is released on the keyboard. KeyDown raises an event when a key is pressed down on the keyboard.
  • 5. Keyboard Events Let’s demonstrate keyboard events in Small Basic with a simple program that allows you to rotate a shape on the graphics window by pressing a key on the keyboard. In this example, you use the Return key on the keyboard to rotate a rectangle shape in the graphics window. When you press the Return key, the rectangle rotates, and on releasing the Return key, the rectangle returns to its original state.
  • 6. Mouse Events Let’s see how we can use these events in a program. MouseDown raises an event when the mouse button is clicked. MouseUp raises an event when the mouse button is released Like keyboard events, you can create programs in Small Basic that work with events based on mouse clicks. Mouse events generate actions in your program with the click of a mouse. MouseMove raises an event when the mouse is moved around in the graphics window.
  • 7. Let’s Summarize… Congratulations! Now you know how to: Use keyboard events in your program. Using mouse events in your program.
  • 8.
  • 9. Insert buttons to draw shapes with the help of the Controls object.
  • 10. Use the MouseDown and MouseMove events to drop shapes in the drawing area.
  • 11. Use If and Else statements to define the actions that take place by clicking the mouse.

Hinweis der Redaktion

  1. Code:Sub keyupIf GraphicsWindow.LastKey = return thenShapes.Rotate(shape1, 0)EndIfEndSubSub keydownIf GraphicsWindow.LastKey = return thenShapes.Rotate(shape1, 90)EndIfEndSub
  2. Notes:In this example, you use the Return key on the keyboard to rotate a rectangle shape in the graphics window. When you press the Return key, the rectangle rotates, and on releasing the Return key, the rectangle returns to its original state. In the editor window, you first enter the code to add a rectangle by using the AddRectangle operation of the Shapes object. Next, you set the location of the rectangle by using the Move operation.Then, you identify the key with which the rectangle can be rotated. You declare the key and assign it a suitable variable name.After that, you use the KeyDown event of the GraphicsWindow object and declare a subroutine to rotate the shape when the key is pressed.Similarly, you use the KeyUp event and declare a subroutine to rotate the shape when the key is released.On clicking Run, your program gets executed. Agraphics window is displayed with a rectangle in the center. When you press the Return key the rectangle rotates; when you release the Return key, the rectangle rotates back to its original position.Code:GraphicsWindow.Height = 300GraphicsWindow.Width = 300GraphicsWindow.Title = "Graphics Window"shape1 = Shapes.AddRectangle(100, 50)Shapes.Move(shape1, 100, 125)return = "Return"GraphicsWindow.KeyDown = keydownGraphicsWindow.KeyUp = keyupSub keydownIf GraphicsWindow.LastKey = return thenShapes.Rotate(shape1, 90)EndIfEndSubSub keyupIf GraphicsWindow.LastKey = return thenShapes.Rotate(shape1, 0)EndIfEndSub
  3.  Solution:GraphicsWindow.Hide()w = 620h = 450GraphicsWindow.CanResize = "False"GraphicsWindow.Width = wGraphicsWindow.Height = hGraphicsWindow.Top = (Desktop.Height-h) / 2GraphicsWindow.Left = (Desktop.Width-w) / 2GraphicsWindow.Show()GraphicsWindow.Title = "Events and interactivity"GUI()Controls.ButtonClicked = MouseActionSub GUI GraphicsWindow.DrawRectangle(10, 10, 600, 320) GraphicsWindow.DrawRectangle(10, 340, 200, 100)GraphicsWindow.DrawRectangle(10, 340, 600, 100)GraphicsWindow.DrawRectangle(370, 340, 150, 100) Triangle = Controls.AddButton("Triangle", 40, 345)Controls.SetSize(Triangle, 120, 30) Rectangle = Controls.AddButton("Rectangle",40,375)Controls.SetSize(Rectangle, 120, 30) Circle = Controls.AddButton("Circle", 40, 405)Controls.SetSize(Circle, 120, 30) Rotate = Controls.AddButton("Rotate", 230, 360)Controls.SetSize(Rotate, 60, 60) Zoom = Controls.AddButton("Zoom", 290, 360)Controls.SetSize(Zoom, 60, 60) FreeHand = Controls.AddButton("Draw", 390, 360)Controls.SetSize(FreeHand, 60, 60) Clear = Controls.AddButton("Clear", 450, 360)Controls.SetSize(Clear, 60, 60) Exit = Controls.AddButton("Exit", 530, 360)Controls.SetSize(Exit, 60, 60) EndSubSub MouseAction x = GraphicsWindow.MouseX y = GraphicsWindow.MouseYGraphicsWindow.PenWidth = 1 If x > 40 And x < 160 Then GraphicsWindow.BrushColor = GraphicsWindow.GetRandomColor() If y > 345 And y < 375 Then draw = 0 j = 0 z = 1 tri = Shapes.AddTriangle(20, 20, 100, 100, 150, 20)Shapes.Move(tri, 80, 100)EndIfIf y > 375 And y < 405 Then draw = 0 j = 0 z = 2 rect = Shapes.AddRectangle(100, 100)Shapes.Move(rect, 250, 150)EndIfIf y > 405 And y < 435 Then draw = 0 j = 0 z = 3 circ = Shapes.AddEllipse(100, 100)Shapes.Move(circ, 400, 150)EndIfEndIfIf y > 360 And y < 420 Then If x > 230 And x < 290 Then draw = 0 If z = 1 Then Shapes.Rotate(tri, 30 + m)ElseIf z = 2 Then Shapes.Rotate(rect,30 + m) ElseIf z = 3 Then Shapes.Rotate(circ, 30 + m) EndifEndifEndif m = m + 30 EndIfIf x > 290 And x < 390 Then draw = 0 i = 0.1 + jIf i < 0.4 Then If z = 1 Then Shapes.Zoom(tri, 1 + i, 1 + i)ElseIf z = 2 Then Shapes.Zoom(rect, 1 + i, 1 + i)ElseIf z = 3 Then Shapes.Zoom(circ, 1 + i, 1 + i) EndIfEndIfEndIf j = j + 0.1EndIfEndIfIf x > 390 And x < 450 Then draw = 1 Paint()EndIfIf x > 450 And x < 510 Then draw = 0 j = 0GraphicsWindow.Clear() GraphicsWindow.BrushColor = "Blue" GUI() draw = 0EndIfIf x > 530 And x < 590 Then draw = 0Program.End()EndIfEndIfEndSubSub PaintIf draw = 1 Then GraphicsWindow.MouseMove = MouseDragElseIf Mouse.IsLeftButtonDown Then MouseAction() EndIfEndIfEndSubSub MouseDragIf draw = 1 then x = GraphicsWindow.MouseX y = GraphicsWindow.MouseYIf x > 10 And x < 600 And y > 10 And y < 320 Then If Mouse.IsLeftButtonDown ThenGraphicsWindow.DrawLine(OrgX, OrgY, x, y)EndIfEndIfOrgX = xOrgY = yEndIfEndSub