Bug in KeyName() function

14 views
Skip to first unread message

Carlo Hogeveen

unread,
Jul 3, 2024, 9:22:57 AM (3 days ago) Jul 3
to Semware @ GoogleGroups

I wasted many hours on tracking down what turns out to be a bug in TSE's KeyName() function.

Its syntax is:
string key_name [30] = KeyName(integer key_code)

Many key_codes will return the same key_name. That is OK!
For context, It made me want to list the key codes per key name:
https://ecarlo.nl/tse/DemosAndTests.html#KeyCodes_per_KeyName
It also made me think, that in general it would be a good macro programming strategie to test for a key name instead of a list of
key codes.
But there I got bugged.

Because what is not OK, is that the same key name can be returned with an upper or lower case letter depending on
whether the key_code was passed as a constant or a variable.

The test macro below demonstrates the bug.

Linux TSE works correctly.
For example, there <CtrlAltShift Ÿ> and <CtrlAltShift ÿ> are consistently recognized as two separate keys.

Carlo



#define BUTTON1 -1
#define BUTTON2 1951
#define BUTTON3 65535
proc Main()
integer key_code = BUTTON1
Warn('Key code'; BUTTON1, ':';
KeyName(BUTTON1);
iif(KeyName(BUTTON1) == KeyName(key_code), '==', '<>');
KeyName(key_code))

key_code = BUTTON2
Warn('Key code'; BUTTON2, ':';
KeyName(BUTTON2);
iif(KeyName(BUTTON2) == KeyName(key_code), '==', '<>');
KeyName(key_code))

key_code = BUTTON3
Warn('Key code'; BUTTON3, ':';
KeyName(BUTTON3);
iif(KeyName(BUTTON3) == KeyName(key_code), '==', '<>');
KeyName(key_code))
PurgeMacro(CurrMacroFilename())
end Main




Reply all
Reply to author
Forward
0 new messages