ricommoditieslib
This library turns a program into a commodity: it is listed by the
Exchange program of the system, which can enable, disable, show, hide
and quit it, and it can have hotkeys that work whichever program is
active. It needs commodities.library of version 37 or later, so
Kickstart 2.04 or later. All commands but CommodityMsgPort work in
Amiga mode only.
MakeCommodity registers the program; then SetHotKey adds hotkeys,
numbered 0 to 15. CommodityEvent fetches the next message without
waiting, WaitCommodity waits for one. HotKeyHit then tells which
hotkey was pressed, and ExchangeMessage which command Exchange sent;
the Cx functions are the values of those commands, and the
Exchange functions compare the last message with one of them.
The library answers every message for the program: a message stays
the current one until the next CommodityEvent or WaitCommodity,
which answers it. A program has one commodity; a second
MakeCommodity returns 0 while the first exists. When the program
ends, the library removes the commodity with its hotkeys. Without
commodities.library, MakeCommodity returns 0.
A commodity with one hotkey that ends when Exchange tells it to:
If MakeCommodity("BlitzCx","Blitz commodity","Prints a hotkey")=0 Then End
SetHotKey 0,"lalt lshift a"
Repeat
VWait
If CommodityEvent
If HotKeyHit=0 Then NPrint "Hotkey"
em.l=ExchangeMessage
EndIf
Until em=CxKillThe fixed bugs of the library are listed in Fixes in ricommoditieslib.
Based on the RI Commodities Library guide by Reflective Images (Red When Excited).
Library number 89.
Commands
CommodityEvent
Fetches the next message of the commodity without waiting. Returns -1 if there was one, else 0.
Function, result .l. No help text.
No arguments.
The message stays the current one for HotKeyHit, ExchangeMessage
and the Exchange functions until the next CommodityEvent or
WaitCommodity, which answers it.
CommodityMsgPort
The address of the message port of the commodity, 0 before MakeCommodity. Works in Blitz mode too.
Function, result .l. Help text: -- returns the message port address
No arguments.
CxAppear
The value 19 of the Exchange command to show the interface of the program, to compare with ExchangeMessage.
Function, result .l. No help text.
No arguments.
CxDisable
The value 15 of the Exchange command to disable the commodity, to compare with ExchangeMessage.
Function, result .l. No help text.
No arguments.
CxDisAppear
The value 21 of the Exchange command to hide the interface of the program, to compare with ExchangeMessage.
Function, result .l. No help text.
No arguments.
CxEnable
The value 17 of the Exchange command to enable the commodity, to compare with ExchangeMessage.
Function, result .l. No help text.
No arguments.
CxKill
The value 23 of the Exchange command to quit the program, to compare with ExchangeMessage.
Function, result .l. No help text.
No arguments.
CxListChange
The value 27 of the message that the list of commodities has changed, to compare with ExchangeMessage.
Function, result .l. No help text.
No arguments.
CxUnique
The value 25 of the message that another program tried to make a commodity of the same name, to compare with ExchangeMessage.
Function, result .l. No help text.
No arguments.
ExchangeAppear
-1 if the message evaluated last by ExchangeMessage or HotKeyHit was the command to show the interface (CxAppear), else 0.
Function, result .l. No help text.
No arguments.
ExchangeDisable
-1 if the message evaluated last by ExchangeMessage or HotKeyHit was the command to disable the commodity (CxDisable), else 0.
Function, result .l. No help text.
No arguments.
ExchangeDisAppear
-1 if the message evaluated last by ExchangeMessage or HotKeyHit was the command to hide the interface (CxDisAppear), else 0.
Function, result .l. No help text.
No arguments.
ExchangeEnable
-1 if the message evaluated last by ExchangeMessage or HotKeyHit was the command to enable the commodity (CxEnable), else 0.
Function, result .l. No help text.
No arguments.
ExchangeKill
-1 if the message evaluated last by ExchangeMessage or HotKeyHit was the command to quit (CxKill), else 0.
Function, result .l. No help text.
No arguments.
ExchangeListChange
-1 if the message evaluated last by ExchangeMessage or HotKeyHit said that the list of commodities has changed (CxListChange), else 0.
Function, result .l. No help text.
No arguments.
ExchangeMessage
The command that Exchange sent with the message fetched last, one of the values of the Cx functions, or 0 if that message was no command or there is none.
Function, result .l. No help text.
No arguments.
ExchangeUnique
-1 if the message evaluated last by ExchangeMessage or HotKeyHit said that another program tried to make a commodity of the same name (CxUnique), else 0.
Function, result .l. No help text.
No arguments.
HotKeyHit
The number of the hotkey of the message fetched last, or -1 if that message was no hotkey or there is none.
Function, result .l. No help text.
No arguments.
MakeCommodity
Registers the program as a commodity and activates it. name$ is the name in the list of Exchange, title$ and description$ the texts Exchange shows for it. Returns -1 on success, 0 on failure.
Statement or function, result .l. Help text: (name$,title$,description$)
Arguments: $, $, $
The name must be unique: if a commodity of that name exists, the
command fails and the other commodity gets the message CxUnique.
Exchange’s show and hide buttons are available for the commodity.
A program has one commodity: while it has one, the command returns 0 and the first stays in use. Without commodities.library the command returns 0.
SetCxStatus
Activates (On, -1) or deactivates (Off, 0) the commodity; an inactive commodity gets no hotkeys. Exchange shows the status.
Statement. Help text: on|off
Arguments: .l
Any value other than -1 and 0 does nothing, and so does the command
before a successful MakeCommodity.
SetHotKey
Adds the hotkey hotkey$, a commodities input description such as "lalt lshift a", with the number hotkeynum from 0 to 15, which HotKeyHit returns. Returns -1 on success, 0 on failure.
Statement or function, result .l. Help text: (hotkeynum,hotkey$)
Arguments: .l, $
A number that is in use replaces the old hotkey. The commodity must
have been made with MakeCommodity. A description that
commodities.library does not understand is a failure.
With runtime error checking, a number outside 0 to 15 stops with the runtime error “Hotkey number must be 0 to 15”. Without it, such a number overwrites other data of the library; -1 removes the commodity.
WaitCommodity
Waits for a message of the commodity and makes it the current one. Returns -1, or 0 before MakeCommodity.
Statement or function, result .l. No help text.
No arguments.
If a message is waiting already, the command takes it at once. The
message fetched before is answered, as with CommodityEvent.