ID:2694120

 BYOND Version: 513 Operating System: Windows 10 Pro Web Browser: Firefox 89.0 Applies to: Dream Maker
 Status: Open Issue hasn't been assigned a status value.
Descriptive Problem Summary:

If the current keyboard layout is RU, then the winset does not work correctly for letters

Numbered Steps to Reproduce Problem:

1. Set RU keyboard layout
2. Use winset to set macros

Code Snippet (if applicable) to Reproduce Problem:
/client/verb/loocc()/client/verb/reset_macros()    erase_all_macros()    for(var/key in list("F4", "L"))        winset(src, "macro-\ref[key]", "parent=macro;name=[key];command=loocc")        world.log << "[winget(src, "macro-\ref[key]", "command;name;")]"/client/proc/erase_all_macros()    var/erase_output = ""    var/list/macro_set = params2list(winget(src, "macro.*", "command")) // The third arg doesnt matter here as we're just removing them all    for(var/k in 1 to length(macro_set))        var/list/split_name = splittext(macro_set[k], ".")        var/macro_name = "[split_name[1]].[split_name[2]]" // [3] is "command"        erase_output = "[erase_output];[macro_name].parent=null"    winset(src, null, erase_output)


Expected Results:

command=loocc;name=F4command=loocc;name=L


Actual Results:

command=loocc;name=F4command=;name=


Does the problem occur:
Every time? Or how often?
In other games?
In other user accounts?
On other computers?

When does the problem NOT occur?

Change manually keyboard layout to EN and reset macros again
 Jun 19, 10:47 am (Edited on Jun 19, 10:55 am) Byond not allow cyrillics key binds but most times does conversion to corresponding latin layout key on client side. And maybe problem that it doesn't always work. Mostly is when users start game while in RU layout, looks like as if DS is losing ЙЦУКЕН/QWERTY key binds and they don't work regardless of layout. But if user start game while in ENG layout, then everything works on both layouts. Something similar with DreamMaker macros editor "Find key" button, maybe can be used for tests.
 Jun 19, 7:30 pm I think your winget may simply be broken. \ref[string] will produce a value that may change if the string you used goes out of scope. I don't think there's a bug here. You shouldn't use \ref on a text value to name your macros. Instead I would use ckey() on the key name.
 Jun 19, 10:42 pm In response to Lummox JR ckey() doesn't help or am I doing something wrong? /client/verb/loocc() world.log << "loocc"/client/verb/reset_macros() for(var/key in list("F1","F2","F3","F4","F5","F6","F7","F8","F9","F10","F11","F12","Q","F")) winset(src, "macro-[ckey(key)]", "parent=macro;name=[key];command=loocc") world.log << "[winget(src, "macro-[ckey(key)]", "command;name;")]"  command=;name=command=;name=command=loocc;name=F3command=loocc;name=F4command=loocc;name=F5command=loocc;name=F6command=loocc;name=F7command=loocc;name=F8command=loocc;name=F9command=loocc;name=F10command=loocc;name=F11command=loocc;name=F12command=;name=command=;name= 
 Jun 19, 11:08 pm /client/verb/loocc() world.log << "loocc"/client/verb/reset_macros() winset(src, "macro-F1", "parent=macro;name=F1;command=loocc") world.log << "[winget(src, "macro-F1", "command;name;")]" winset(src, "macro-F2", "parent=macro;name=F2;command=loocc") world.log << "[winget(src, "macro-F2", "command;name;")]" winset(src, "macro-F3", "parent=macro;name=F3;command=loocc") world.log << "[winget(src, "macro-F3", "command;name;")]" winset(src, "macro-Q", "parent=macro;name=Q;command=loocc") world.log << "[winget(src, "macro-Q", "command;name;")]"  command=;name=command=;name=command=loocc;name=F3command=;name= 
 Jun 19, 11:27 pm /client/verb/loocc() world.log << "loocc"/client/verb/reset_macros() for(var/key in list("Q","W","F1","F2")) winset(src, "macro.[key]", "parent=macro;name=[key];command=loocc") world.log << "[winget(src, "macro.[key]", "command;name;")]"  // RU keyboard layout oncommand=;name=command=;name=command=loocc;name=F1command=loocc;name=F2// EN keyboard layout oncommand=loocc;name=Qcommand=loocc;name=Wcommand=loocc;name=F1command=loocc;name=F2 
 Jun 20, 10:03 am You might try using _ instead of - in the ID. Better to stick with characters that would be valid in a var name. The keyboard layout has no impact whatsoever on the code that handles macro winsets/wingets; it would at most be relevant to the way macros triggered.
 Jun 20, 1:22 pm This is not naming Problem. Macros do not work if the client has the Russian layout enabled at the time of the winset run /client/verb/loocc() world.log << "loocc"/client/New() ..() winset(src, "macro_Q", "parent=macro;name=Q;command=loocc") world.log << "[winget(src, "macro_Q", "command;name;")]"  command=;name= 
 Jun 20, 7:29 pm Well one of the major problems here is that you can't use winset() or winget() reliably in client/New(). Those should be done at the mob/Login() stage. But the way macros are set on the client via winset(), and retrieved via winget(), is completely agnostic as to the current keyboard layout. The only thing that would make a lick of sense here would be if there were some really bizarre parsing or character conversion issue in play with how the command is handled, but that doesn't make a ton of sense, plus it also isn't something I can readily test.
 Jun 20, 9:16 pm In response to Lummox JR Above, I gave examples when I set macros using verbs when the Russian layout is active. And at the mob/Login() stage doesn't work either
 Jun 22, 10:30 am I'm still having a lot of trouble diagnosing this. I may not be able to do it without downloading a Russian keyboard layout, which I'm kinda loath to do. I was thinking your locale might matter in terms of parsing the winset and some uppercase/lowercase conversion that the macro code does. The backend code however actually switches out of your default locale right away, and switches to the internal "C" locale that produces more predictable results. The only time your original locale should be taken into account is when using certain date/time functions or when converting between "ANSI" text (8-bit for whatever code page your system uses) and UTF-8. So ultimately I can't explain the results you're getting.
 Jun 23, 12:03 am I can approve that this issue is highly reproducible with all our Russian players on our Russian server for years.
 Jun 23, 12:12 am Also, I just have found, that some players reported that their custom macroses are reset when they join the game with the Russian layout turned on: https://github.com/ChaoticOnyx/OnyxBay/issues/5400 (report in Russian) They managed to fix it by pressing "Cancel", reopening macroses menu with English layout, and pressing "Ok".
 Jun 23, 10:06 am I'm beginning to suspect the use of VkKeyScan() is causing this issue. Can you tell me if the problem first appeared in 513 or if it was earlier? I'm not sure why 513 would have changed this of course, except for switching on Unicode functionality.
 Jun 23, 12:31 pm In response to Lummox JR Lummox JR wrote: I'm beginning to suspect the use of VkKeyScan() is causing this issue. Can you tell me if the problem first appeared in 513 or if it was earlier? I'm not sure why 513 would have changed this of course, except for switching on Unicode functionality. This bug exists for ages tbh
 Jun 24, 1:15 am Yeah, that's true. It's not the 513's issue, it has been existing long before.