Page 1 of 2
SetKeyMapDefault() changes "global" keymap?
Posted: Tue Oct 15, 2013 11:34 pm
by javierdlr
Hi, testing keymap.library (SDK) and using ObtainKeyMapInfo() I can get whatever KEYMAP: I want/need, but how does SetKeyMapDefault() work?
Does SetKeyMapDefault() change globally in my system the KEYMAP I want/need?
How? The code example below shows 'KEYMAP:usa_ISO-8859-15' info/data OK, but if I try to change my keymap from e_ISO-8859-15 (defined in input.prefs) to 'usa_ISO-8859-15' with SetKeyMapDefault() seems nothing happens.
Code: Select all
int main(void)
{
ULONG KM_res;
APTR KM_handle;
STRPTR KM_name, KM_localname;
//struct KeyMap *km = NULL;
struct KeyMapNode *kmn = NULL;
..
open KeymapBase & IFace
..
KM_handle = IKeymap->OpenKeyMapHandle("KEYMAP:usa_ISO-8859-15", NULL);
KM_res = IKeymap->ObtainKeyMapInfo(KM_handle,
KEYMAPINFO_KEYMAPNODE, &kmn,
KEYMAPINFO_INFOTEXT_ENGLISH, &KM_name,
KEYMAPINFO_INFOTEXT_LOCAL, &KM_localname,
TAG_END);
IDOS->Printf("(0x%08lx) %s | %s\n",kmn->kn_KeyMap,KM_name,KM_localname);
IKeymap->SetKeyMapDefault(kmn->kn_KeyMap);
..
close KeymapBase & IFace
..
return(0);
}
BTW: how can I retrive my default keymap name and localname?
BTW2: must I ReleaseKeyMapInfo() if I use ObtainKeyMapInfo() in my code?
TIA
Re: SetKeyMapDefault() changes "global" keymap?
Posted: Thu Oct 17, 2013 9:22 pm
by trixie
Could it be because SetKeyMapDefault() expects a POINTER to struct KeyMap as parameter, whereas your kmn->kn_KeyMap provides the actual structure (not a pointer to it)? You must pass the address of the kn_KeyMap field, using the & operator.
Re: SetKeyMapDefault() changes "global" keymap?
Posted: Thu Oct 17, 2013 10:33 pm
by salass00
To add to what trixie wrote you are not allowed to free the keymap after you have used it with SetKeyMapDefault() (this fact is stated in the autodoc).
Re: SetKeyMapDefault() changes "global" keymap?
Posted: Fri Oct 18, 2013 11:40 am
by javierdlr
trixie wrote:Could it be because SetKeyMapDefault() expects a POINTER to struct KeyMap as parameter, whereas your kmn->kn_KeyMap provides the actual structure (not a pointer to it)? You must pass the address of the kn_KeyMap field, using the & operator.
Ooops, YES thx that solved.
BTW if I use 'keyMap = AskKeyMapDefault()' can then I use (pseudo_code):
Code: Select all
struct KeyMapNode
{
struct Node kn_Node; /* including name of keymap */
struct KeyMap kn_KeyMap;
} kmn;
kmn->kn_KeyMap = keyMap;
so I get the 'name of the keymap'?
well just trying it now to see what happens...
THX
Re: SetKeyMapDefault() changes "global" keymap?
Posted: Fri Oct 18, 2013 11:43 am
by javierdlr
salass00 wrote:To add to what trixie wrote you are not allowed to free the keymap after you have used it with SetKeyMapDefault() (this fact is stated in the autodoc).
Yes, you're right, now I see.
And if I use ObtainKeyMapInfo() only to create a list/table, then I must use ReleaseKeyMapInfo() after each ObtainKeyMapInfo() read?
Re: SetKeyMapDefault() changes "global" keymap?
Posted: Fri Oct 18, 2013 3:18 pm
by trixie
@javierdl
No, I'm afraid you got it all wrong. Do you use MemGuard when developing? You program must be trashing memory all along the watchtower!
if I use 'keyMap = AskKeyMapDefault()' can then I use (pseudo_code):
Code: Select all
struct KeyMapNode
{
struct Node kn_Node; /* including name of keymap */
struct KeyMap kn_KeyMap;
} kmn;
kmn->kn_KeyMap = keyMap;
First, your
kmn is declared as a physical structure KeyMapNode here (not as a pointer to this structure), so you cannot use the -> operator to access its members (fields). Second, the
kn_KeyMap field is declared as a physical structure KeyMap, so you cannot initialize it with your result from AskKeyMapDefault() because the result is a pointer.
so I get the 'name of the keymap'?
Still, even if you fix the problems above, this approach will get you nowhere. The name of the keymap is stored in the
ln_Name field of the Node structure that is embedded in struct KeyMapNode. But function AskKeyMapDefault() has no knowledge of struct KeyMapNode so it cannot possibly supply the name of the default keymap in the
ln_Name field.
Re: SetKeyMapDefault() changes "global" keymap?
Posted: Fri Oct 18, 2013 3:55 pm
by javierdlr
trixie wrote:@javierdl
No, I'm afraid you got it all wrong. Do you use MemGuard when developing? You program must be trashing memory all along the watchtower!
Nop, but the os4 internal MUNGE option.
Still, even if you fix the problems above, this approach will get you nowhere. The name of the keymap is stored in the ln_Name field of the Node structure that is embedded in struct KeyMapNode. But function AskKeyMapDefault() has no knowledge of struct KeyMapNode so it cannot possibly supply the name of the default keymap in the ln_Name field.
OK, so now there is no "direct" function/way to get default keyboard name/charset/...
Right now I'm reading 'ENV:input.prefs' and getting the variables/data I need using the example from the wiki
http://wiki.amigaos.net/index.php/Prefe ... ences_File
THX for all the help mate
Re: SetKeyMapDefault() changes "global" keymap?
Posted: Fri Oct 18, 2013 4:04 pm
by trixie
javierdlr wrote:
OK, so now there is no "direct" function/way to get default keyboard name/charset/...
Possibly not. I'm quite surprised that OpenKeyMapHandleA() does not accept a NULL name argument, in which case the function would return handle to the current default keymap. This way you could get your KeyMapNode and, thus, the name of the default keymap as well. Time for an enhancement request perhaps?
As for charset, you can read the system env-var called "Charset" (I think).
Re: SetKeyMapDefault() changes "global" keymap?
Posted: Sat Oct 19, 2013 1:30 pm
by chris
trixie wrote:As for charset, you can read the system env-var called "Charset" (I think).
It's better to use GetDiskFontCtrl().
Re: SetKeyMapDefault() changes "global" keymap?
Posted: Sat Oct 19, 2013 9:13 pm
by trixie
@chris
This function should never be called by the average user. Its sole purpose is to provide the font preferences editor with data about the current diskfont settings. It should not be called for other purposes.
The GetDiskFontCtrl() autodoc doesn't sound very encouraging, though
