I have discovered that my previous script actually doesn’t solve the problem with hotkeys. It just allows keyboard layouts different from the standard “US” one (including the “Colemak Multilingual” layout itself) to be used on systems where registry remapping technique had been applied. That script remaps the key scan codes, whereas in order for the hotkeys to work in non-latin layouts, we have to modify virtual key codes as well. So here are two more scripts:
#File name: 'colemakVkRemap.py'
import sys
assert len(sys.argv) == 3, ('Usage: "python colemakVkRemap.py '
'<input klc file path> <output klc file path>"')
srcFilePath = sys.argv[1]
dstFilePath = sys.argv[2]
assert srcFilePath.endswith('.klc') and dstFilePath.endswith('.klc')
virtualKeyMap = {
'E' : 'F',
'R' : 'P',
'T' : 'G',
'Y' : 'J',
'U' : 'L',
'I' : 'U',
'O' : 'Y',
'P' : 'OEM_1',
'S' : 'R',
'D' : 'S',
'F' : 'T',
'G' : 'D',
'J' : 'N',
'K' : 'E',
'L' : 'I',
'OEM_1' : 'O',
'N' : 'K',
}
with open(srcFilePath, encoding = 'utf16') as srcFile:
with open(dstFilePath, 'w', encoding = 'utf16') as dstFile:
for line in srcFile:
for key in virtualKeyMap:
if line[2 :].startswith('\t' + key + '\t'):
line = (line[0 : 3] + virtualKeyMap[key] +
line[3 + len(key) :])
break
line = line.replace('- Custom', '- Colemak-remapped')
dstFile.write(line)
This script modifies virtual key codes, but leaves scan codes intact. It probably implements the approach taken by pafkata90. It is intended for those users of non-latin layouts that are not using the registry remapping.
I have tried this approach with Microsoft Word under a Russian layout, and it seems that everything is working just the way I need (that is, both Ctrl and Alt key combinations, as well as hotkeys in the Ribbon interface, work identically to the Colemak layout). So I’ll probably stick to this very solution instead of the registry remapping that I’ve been using recently.
#File name: 'colemakVkScRemap.py'
import sys
assert len(sys.argv) == 3, ('Usage: "python colemakVkScRemap.py '
'<input klc file path> <output klc file path>"')
srcFilePath = sys.argv[1]
dstFilePath = sys.argv[2]
assert srcFilePath.endswith('.klc') and dstFilePath.endswith('.klc')
virtualKeyMap = {
'E' : 'F',
'R' : 'P',
'T' : 'G',
'Y' : 'J',
'U' : 'L',
'I' : 'U',
'O' : 'Y',
'P' : 'OEM_1',
'S' : 'R',
'D' : 'S',
'F' : 'T',
'G' : 'D',
'J' : 'N',
'K' : 'E',
'L' : 'I',
'OEM_1' : 'O',
'N' : 'K',
}
scanCodeMap = {
'12' : '21',
'13' : '19',
'14' : '22',
'15' : '24',
'16' : '26',
'17' : '16',
'18' : '15',
'19' : '27',
'1f' : '13',
'20' : '1f',
'21' : '14',
'22' : '20',
'24' : '31',
'25' : '12',
'26' : '17',
'27' : '18',
'31' : '25',
}
with open(srcFilePath, encoding = 'utf16') as srcFile:
with open(dstFilePath, 'w', encoding = 'utf16') as dstFile:
for line in srcFile:
for key in virtualKeyMap:
if line[2 :].startswith('\t' + key + '\t'):
line = (line[0 : 3] + virtualKeyMap[key] +
line[3 + len(key) :])
break
for key in scanCodeMap:
if line.startswith(key + '\t'):
line = scanCodeMap[key] + line[2 :]
break
line = line.replace('- Custom', '- for registry-remapped Colemak')
dstFile.write(line)
This script modifies both scan codes and virtual keys. It is intended for those people who use registry remapping and want to use existing non-latin layouts with hotkeys mapped to the Colemak layout.
Last edited by JanK (29-Sep-2012 20:11:58)