User Tools

Site Tools


creating_20function_20key_20macros

Differences

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

Link to this comparison view

creating_20function_20key_20macros [2018/03/31 13:19]
127.0.0.1 external edit
creating_20function_20key_20macros [2018/04/15 18:41] (current)
tbest3112 Added syntax highlighting
Line 15: Line 15:
   HKEY_CURRENT_USER\Software\R T Russell\BBC BASIC for Windows\Macros\F12   HKEY_CURRENT_USER\Software\R T Russell\BBC BASIC for Windows\Macros\F12
 When one of the keys is pressed the corresponding Registry entry is checked, and if present the macro string stored there is executed.\\ \\  The string associated with a particular macro can be of any (reasonable) length and contains the usual 8-bit (ANSI) character codes corresponding to the required sequence of key-presses. Any character which can be obtained from the keyboard (including those which require the **Shift** and/or **Ctrl** keys to be pressed) may be included in the string. However, character codes which cannot be directly obtained from the keyboard must __not__ be included.\\ \\  So to program the **F12** key to generate **Hello world!** one could use the following simple program:​\\ ​ When one of the keys is pressed the corresponding Registry entry is checked, and if present the macro string stored there is executed.\\ \\  The string associated with a particular macro can be of any (reasonable) length and contains the usual 8-bit (ANSI) character codes corresponding to the required sequence of key-presses. Any character which can be obtained from the keyboard (including those which require the **Shift** and/or **Ctrl** keys to be pressed) may be included in the string. However, character codes which cannot be directly obtained from the keyboard must __not__ be included.\\ \\  So to program the **F12** key to generate **Hello world!** one could use the following simple program:​\\ ​
 +<code bb4w>
         Macro12$ = "Hello world!"​         Macro12$ = "Hello world!"​
  
Line 23: Line 24:
           SYS "​RegCloseKey",​ K%           SYS "​RegCloseKey",​ K%
         ENDIF         ENDIF
 +</​code>​
 Of course there are several keyboard keys which do not generate characters, but which either modify the action of other keys (e.g. **Shift**, **Ctrl**, **Alt**) or have special actions such as cursor movement or Escape. The function keys themselves are in this category. It is possible to incorporate these keys into a macro string using the special values **CHR$0** or **CHR$255** followed immediately by the [[http://​www.kbdedit.com/​manual/​low_level_vk_list.html|Virtual Key code]] of the key concerned. In the first case (CHR$0+VKcode$) the effect is to **press** the (virtual) key and in the second (CHR$255+VKcode$) to **release** it.\\ \\  So to program the **F11** key so that it alternately adds and removes line numbers to the current program you can do the following:​\\ ​ Of course there are several keyboard keys which do not generate characters, but which either modify the action of other keys (e.g. **Shift**, **Ctrl**, **Alt**) or have special actions such as cursor movement or Escape. The function keys themselves are in this category. It is possible to incorporate these keys into a macro string using the special values **CHR$0** or **CHR$255** followed immediately by the [[http://​www.kbdedit.com/​manual/​low_level_vk_list.html|Virtual Key code]] of the key concerned. In the first case (CHR$0+VKcode$) the effect is to **press** the (virtual) key and in the second (CHR$255+VKcode$) to **release** it.\\ \\  So to program the **F11** key so that it alternately adds and removes line numbers to the current program you can do the following:​\\ ​
 +<code bb4w>
         Alt_Down$ = CHR$0+CHR$18         Alt_Down$ = CHR$0+CHR$18
         Alt_Up$ = CHR$255+CHR$18         Alt_Up$ = CHR$255+CHR$18
Line 36: Line 39:
           SYS "​RegCloseKey",​ K%           SYS "​RegCloseKey",​ K%
         ENDIF         ENDIF
 +</​code>​
 This corresponds to the following sequence of keyboard operations:​\\ \\  This corresponds to the following sequence of keyboard operations:​\\ \\ 
  
Line 45: Line 49:
   - Press Enter (activate the OK button)   - Press Enter (activate the OK button)
 \\  Note that you should always use the **press** and **release** codes in pairs, so the macro leaves the '​virtual keyboard'​ in the same state that it found it.\\ \\  You can even create a macro that executes a BASIC program, by generating a sequence of keypresses which will enter '​immediate mode' and run the program from there:​\\ ​ \\  Note that you should always use the **press** and **release** codes in pairs, so the macro leaves the '​virtual keyboard'​ in the same state that it found it.\\ \\  You can even create a macro that executes a BASIC program, by generating a sequence of keypresses which will enter '​immediate mode' and run the program from there:​\\ ​
 +<code bb4w>
         Alt_Down$ = CHR$0+CHR$18         Alt_Down$ = CHR$0+CHR$18
         Alt_Up$ = CHR$255+CHR$18         Alt_Up$ = CHR$255+CHR$18
Line 57: Line 62:
           SYS "​RegCloseKey",​ K%           SYS "​RegCloseKey",​ K%
         ENDIF         ENDIF
 +</​code>​
 The corresponding keyboard sequence is as follows:\\ \\  The corresponding keyboard sequence is as follows:\\ \\ 
  
creating_20function_20key_20macros.txt ยท Last modified: 2018/04/15 18:41 by tbest3112