User Tools

Site Tools


effect_20of_20get_20and_20input_20on_20event_20handling

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

effect_20of_20get_20and_20input_20on_20event_20handling [2018/03/31 13:19]
127.0.0.1 external edit
effect_20of_20get_20and_20input_20on_20event_20handling [2018/04/16 10:52] (current)
richardrussell Added syntax highlighting
Line 1: Line 1:
 =====Effect of GET and INPUT on event handling===== =====Effect of GET and INPUT on event handling=====
  
-//by Jon Ripley and Richard Russell, April 2007//\\ \\  The functions **GET** and **GET$**, and the statement **INPUT**, can adversely affect the handling of //events// (e.g. [[http://​www.bbcbasic.co.uk/​bbcwin/​manual/​bbcwin6.html#​onclose|ON CLOSE]], [[http://​www.bbcbasic.co.uk/​bbcwin/​manual/​bbcwin6.html#​onmouse|ON MOUSE]] etc.) by your program. This is because whilst they are waiting for user input no events will be processed.\\ \\  The following program demonstrates this issue. Run this program in the IDE and you will notice that clicking on the close icon has no effect until you press a key:\\ \\ +//by Jon Ripley and Richard Russell, April 2007//\\ \\  The functions **GET** and **GET$**, and the statement **INPUT**, can adversely affect the handling of //events// (e.g. [[http://​www.bbcbasic.co.uk/​bbcwin/​manual/​bbcwin6.html#​onclose|ON CLOSE]], [[http://​www.bbcbasic.co.uk/​bbcwin/​manual/​bbcwin6.html#​onmouse|ON MOUSE]] etc.) by your program. This is because whilst they are waiting for user input no events will be processed.\\ \\  The following program demonstrates this issue. Run this program in the IDE and you will notice that clicking on the close icon has no effect until you press a key: 
 + 
 +<code bb4w> ​
         ON CLOSE QUIT         ON CLOSE QUIT
         PRINT GET         PRINT GET
-In the case of **GET** and **GET$** the problem can be solved by using the functions **FNget** and **FNget$** listed below, which are equivalent to GET and GET$ but do not interfere with event handling:\\ \\ +</​code>​ 
 + 
 +In the case of **GET** and **GET$** the problem can be solved by using the functions **FNget** and **FNget$** listed below, which are equivalent to GET and GET$ but do not interfere with event handling: 
 + 
 +<code bb4w>
         DEF FNget:​LOCALK%         DEF FNget:​LOCALK%
         REPEAT WAIT 0:​K%=INKEY(0):​UNTILK%>​0         REPEAT WAIT 0:​K%=INKEY(0):​UNTILK%>​0
Line 12: Line 18:
         REPEAT WAIT 0:​K$=INKEY$(0):​UNTILK$>""​         REPEAT WAIT 0:​K$=INKEY$(0):​UNTILK$>""​
         =K$         =K$
-The following code demonstrates how to call these functions:\\ \\ +</​code>​ 
 + 
 +The following code demonstrates how to call these functions: 
 + 
 +<code bb4w>
         N = FNget         N = FNget
         N$ = FNget$         N$ = FNget$
-Solving the problem with **INPUT** is more difficult, because of the many facilities provided by that statement (input editing, pasting from the clipboard, copy key etc.). To reproduce the full functionality of **INPUT** in BBC BASIC code would be challenging,​ but often your program will not require all its facilities.\\ \\  The function **FNinput** below provides a replacement for **INPUT** with simple line-editing facilities which may often be sufficient:\\ \\ +</​code>​ 
 + 
 +Solving the problem with **INPUT** is more difficult, because of the many facilities provided by that statement (input editing, pasting from the clipboard, copy key etc.). To reproduce the full functionality of **INPUT** in BBC BASIC code would be challenging,​ but often your program will not require all its facilities.\\ \\  The function **FNinput** below provides a replacement for **INPUT** with simple line-editing facilities which may often be sufficient: 
 + 
 +<code bb4w>
         DEF FNinput         DEF FNinput
         LOCAL a$,​c%,​k%,​x%,​y%         LOCAL a$,​c%,​k%,​x%,​y%
Line 35: Line 49:
         PRINT         PRINT
         =a$         =a$
-If you need the ability to paste from the clipboard, you can do that by adding the following line to the **CASE** statement:\\ \\ +</​code>​ 
 + 
 +If you need the ability to paste from the clipboard, you can do that by adding the following line to the **CASE** statement: 
 + 
 +<code bb4w>
             WHEN 22: PROCpaste(a$,​c%)             WHEN 22: PROCpaste(a$,​c%)
-and adding the procedure **PROCpaste** as follows:\\ \\ +</​code>​ 
 + 
 +and adding the procedure **PROCpaste** as follows: 
 + 
 +<code bb4w>
         DEF PROCpaste(RETURN a$,RETURN c%)         DEF PROCpaste(RETURN a$,RETURN c%)
         LOCAL r%,h%,t%         LOCAL r%,h%,t%
Line 53: Line 75:
         SYS "​CloseClipboard"​         SYS "​CloseClipboard"​
         ENDPROC         ENDPROC
-The following code demonstrates how to call **FNinput** from your program:\\ \\ +</​code>​ 
 + 
 +The following code demonstrates how to call **FNinput** from your program: 
 + 
 +<code bb4w>
         PRINT "​Prompt:​ ";         PRINT "​Prompt:​ ";
         reply$ = FNinput         reply$ = FNinput
 +</​code>​
 +
 A more comprehensive version of **FNinput**,​ supporting features such as toggling between insert and overtype modes, can be found in the [[http://​groups.yahoo.com/​group/​bb4w/​files/​Libraries/​NOWAIT.BBC|NOWAIT]] library. A more comprehensive version of **FNinput**,​ supporting features such as toggling between insert and overtype modes, can be found in the [[http://​groups.yahoo.com/​group/​bb4w/​files/​Libraries/​NOWAIT.BBC|NOWAIT]] library.
effect_20of_20get_20and_20input_20on_20event_20handling.txt · Last modified: 2018/04/16 10:52 by richardrussell