Edited at

SMKD92(メカニカル左手キーボード)にツータッチマクロを割り当てるUSBキーボードのHIDコード確認

More than 1 year has passed since last update.


メカニカルキーボードSMKD92に全キーを割り当てる為、以下のツータッチマクロを考えた


定義したいこと


FN1+以下を登録

j 1

k 2

l 3

- 4

^ 5

F1 6

F2 7

F3 8

F4 9

F5 0

q UP

w DOWN

a LEFT

s RIGHT

f ;

g :

h *

v +

b -

n =

ENT @

t `

r "

e '

CAPS (

BS )

面倒なので以下のTowKeyClickファイルデータ形式に合わせてデータを作成するSQLを作る

この作成ファイルをThumbkeyboard Configration ツールの「TowKeyClick Edit」で読み込ませてSMKD92に書き込む。


TowKeyClickファイルデータ形式


towkeydef.txt

 ##ヘッダ行:

0x92, 0x02, 0x00, 0x01,
{32個の定義レコード}

##定義レコード:
0x04, 0x16, 0x00, 0x50, 0x00, 0x00, 0x00, 0x00,
1個目:ツータッチのキー1のHIDコード(HEX)
2個目:ツータッチのキー2のHIDコード(HEX)
3個目:表したいキーで、組み合わせキーの有無でそのコード(SHIFTなら0x02、無ければ0x00)セット
4個目:表したいキーのHIDコード(HEX)「1文字目」
5個目:表したいキーのHIDコード(HEX)「2文字目」(バースト文字出ししたいとき移行をセット)
6個目:表したいキーのHIDコード(HEX)「3文字目」(〃)
7個目:表したいキーのHIDコード(HEX)「4文字目」(〃)
8個目:表したいキーのHIDコード(HEX)「5文字目」(〃)



そのためのSQL

HIDキーボードの定義は以下サイトを参照した。

http://www2d.biglobe.ne.jp/~msyk/keyboard/layout/usbkeycode.html


with句のクエリブロックは、前に定義されて居れば次のブロック内で参照可能。


list.sql

with HIDDEFS as (--以下がHID USBキーコードをNOとキーサーフェスとその定義コード(07 / HEXとか)をUNIONクエリ

select a.*,
regexp_replace(a.CODES,'^.+[ ]([0-9|A-F]+)$','\1') hexs
from (
select '1' no,'半角/全角' keyface,'07 / 35' codes from dual
union select '2' no,'1 !' keyface,'07 / 1E' codes from dual
union select '3' no,'2 "' keyface,'07 / 1F' codes from dual
union select '4' no,'3 #' keyface,'07 / 20' codes from dual
union select '5' no,'4 $' keyface,'07 / 21' codes from dual
union select '6' no,'5 %' keyface,'07 / 22' codes from dual
union select '7' no,'6 &' keyface,'07 / 23' codes from dual
union select '8' no,'7 ’' keyface,'07 / 24' codes from dual
union select '9' no,'8 (' keyface,'07 / 25' codes from dual
union select '10' no,'9 )' keyface,'07 / 26' codes from dual
union select '11' no,'0' keyface,'07 / 27' codes from dual
union select '12' no,'- =' keyface,'07 / 2D' codes from dual
union select '13' no,'^ ~' keyface,'07 / 2E' codes from dual
union select '14' no,'¥ |' keyface,'07 / 89' codes from dual
union select '15' no,'Backspace' keyface,'07 / 2A' codes from dual
union select '16' no,'Tab' keyface,'07 / 2B' codes from dual
union select '17' no,'Q' keyface,'07 / 14' codes from dual
union select '18' no,'W' keyface,'07 / 1A' codes from dual
union select '19' no,'E' keyface,'07 / 08' codes from dual
union select '20' no,'R' keyface,'07 / 15' codes from dual
union select '21' no,'T' keyface,'07 / 17' codes from dual
union select '22' no,'Y' keyface,'07 / 1C' codes from dual
union select '23' no,'U' keyface,'07 / 18' codes from dual
union select '24' no,'I' keyface,'07 / 0C' codes from dual
union select '25' no,'O' keyface,'07 / 12' codes from dual
union select '26' no,'P' keyface,'07 / 13' codes from dual
union select '27' no,'@ `' keyface,'07 / 2F' codes from dual
union select '28' no,'[ {' keyface,'07 / 30' codes from dual
union select '29' no,'-----' keyface,'07 / 31' codes from dual
union select '30' no,'英数 Caps Lock' keyface,'07 / 39' codes from dual
union select '31' no,'A' keyface,'07 / 04' codes from dual
union select '32' no,'S' keyface,'07 / 16' codes from dual
union select '33' no,'D' keyface,'07 / 07' codes from dual
union select '34' no,'F' keyface,'07 / 09' codes from dual
union select '35' no,'G' keyface,'07 / 0A' codes from dual
union select '36' no,'H' keyface,'07 / 0B' codes from dual
union select '37' no,'J' keyface,'07 / 0D' codes from dual
union select '38' no,'K' keyface,'07 / 0E' codes from dual
union select '39' no,'L' keyface,'07 / 0F' codes from dual
union select '40' no,'; +' keyface,'07 / 33' codes from dual
union select '41' no,': *' keyface,'07 / 34' codes from dual
union select '42' no,'] }' keyface,'07 / 32' codes from dual
union select '43' no,'Enter' keyface,'07 / 28' codes from dual
union select '44' no,'Left Shift' keyface,'07 / E1' codes from dual
union select '46' no,'Z' keyface,'07 / 1D' codes from dual
union select '47' no,'X' keyface,'07 / 1B' codes from dual
union select '48' no,'C' keyface,'07 / 06' codes from dual
union select '49' no,'V' keyface,'07 / 19' codes from dual
union select '50' no,'B' keyface,'07 / 05' codes from dual
union select '51' no,'N' keyface,'07 / 11' codes from dual
union select '52' no,'M' keyface,'07 / 10' codes from dual
union select '53' no,', <' keyface,'07 / 36' codes from dual
union select '54' no,'. >' keyface,'07 / 37' codes from dual
union select '55' no,'/ ?' keyface,'07 / 38' codes from dual
union select '56' no,'\ _' keyface,'07 / 87' codes from dual
union select '57' no,'Right Shift' keyface,'07 / E5' codes from dual
union select '58' no,'Left Ctrl' keyface,'07 / E0' codes from dual
union select '60' no,'Left Alt' keyface,'07 / E2' codes from dual
union select '61' no,'Spacebar' keyface,'07 / 2C' codes from dual
union select '62' no,'Right Alt' keyface,'07 / E6' codes from dual
union select '64' no,'Right Ctrl' keyface,'07 / E4' codes from dual
union select '75' no,'Insert' keyface,'07 / 49' codes from dual
union select '76' no,'Delete' keyface,'07 / 4C' codes from dual
union select '79' no,'←' keyface,'07 / 50' codes from dual
union select '80' no,'Home' keyface,'07 / 4A' codes from dual
union select '81' no,'End' keyface,'07 / 4D' codes from dual
union select '83' no,'↑' keyface,'07 / 52' codes from dual
union select '84' no,'↓' keyface,'07 / 51' codes from dual
union select '85' no,'Page Up' keyface,'07 / 4B' codes from dual
union select '86' no,'Page Down' keyface,'07 / 4E' codes from dual
union select '89' no,'→' keyface,'07 / 4F' codes from dual
union select '90' no,'Num Lock' keyface,'07 / 53' codes from dual
union select '91' no,'Keypad 7' keyface,'07 / 5F' codes from dual
union select '92' no,'Keypad 4' keyface,'07 / 5C' codes from dual
union select '93' no,'Keypad 1' keyface,'07 / 59' codes from dual
union select '95' no,'Keypad /' keyface,'07 / 54' codes from dual
union select '96' no,'Keypad 8' keyface,'07 / 60' codes from dual
union select '97' no,'Keypad 5' keyface,'07 / 5D' codes from dual
union select '98' no,'Keypad 2' keyface,'07 / 5A' codes from dual
union select '99' no,'Keypad 0' keyface,'07 / 62' codes from dual
union select '100' no,'Keypad *' keyface,'07 / 55' codes from dual
union select '101' no,'Keypad 9' keyface,'07 / 61' codes from dual
union select '102' no,'Keypad 6' keyface,'07 / 5E' codes from dual
union select '103' no,'Keypad 3' keyface,'07 / 5B' codes from dual
union select '104' no,'Keypad .' keyface,'07 / 63' codes from dual
union select '105' no,'Keypad -' keyface,'07 / 56' codes from dual
union select '106' no,'Keypad +' keyface,'07 / 57' codes from dual
union select '108' no,'Keypad Enter' keyface,'07 / 58' codes from dual
union select '110' no,'Esc' keyface,'07 / 29' codes from dual
union select '112' no,'F1' keyface,'07 / 3A' codes from dual
union select '113' no,'F2' keyface,'07 / 3B' codes from dual
union select '114' no,'F3' keyface,'07 / 3C' codes from dual
union select '115' no,'F4' keyface,'07 / 3D' codes from dual
union select '116' no,'F5' keyface,'07 / 3E' codes from dual
union select '117' no,'F6' keyface,'07 / 3F' codes from dual
union select '118' no,'F7' keyface,'07 / 40' codes from dual
union select '119' no,'F8' keyface,'07 / 41' codes from dual
union select '120' no,'F9' keyface,'07 / 42' codes from dual
union select '121' no,'F10' keyface,'07 / 43' codes from dual
union select '122' no,'F11' keyface,'07 / 44' codes from dual
union select '123' no,'F12' keyface,'07 / 45' codes from dual
union select '124' no,'Print Screen' keyface,'07 / 46' codes from dual
union select '125' no,'Scroll Lock' keyface,'07 / 47' codes from dual
union select '126' no,'Pause' keyface,'07 / 48' codes from dual
union select '127' no,'Left Windows' keyface,'07 / E3' codes from dual
union select '128' no,'Right Windows' keyface,'07 / E7' codes from dual
union select '129' no,'Application' keyface,'07 / 65' codes from dual
union select '131' no,'無変換' keyface,'07 / 8B' codes from dual
union select '132' no,'変換' keyface,'07 / 8A' codes from dual
union select '133' no,'ひらがな カタカナ' keyface,'07 / 88' codes from dual
union select '300' no,'-----' keyface,'07 / 68' codes from dual
union select '301' no,'-----' keyface,'07 / 69' codes from dual
union select '302' no,'-----' keyface,'07 / 6A' codes from dual
union select '303' no,'-----' keyface,'07 / 67' codes from dual
union select '304' no,'-----' keyface,'07 / 85' codes from dual
union select '305' no,'-----' keyface,'07 / 91' codes from dual
union select '306' no,'-----' keyface,'07 / 90' codes from dual
union select '400' no,'-----' keyface,'0C / 00EA' codes from dual
union select '401' no,'-----' keyface,'0C / 00E9' codes from dual
union select '402' no,'-----' keyface,'0C / 00E2' codes from dual
union select '403' no,'-----' keyface,'0C / 00B8' codes from dual
) a)
--==============================================
,HIDFFSCODES as (--以下がHID USBキーコードをNOとキーサーフェスとその定義コードを付加
select * from (
select c.NO,c.KEYFACE,c.HEXS HID_CODE_HEX,d.DECS HID_CODE_DEC
FROM (
select
b.NO,b.KEYFACE,b.HEXS
from HIDDEFS b
) c
,(select a.NO,a.MBHDEC*16+a.MBLDEC decs
from (
select a.NO
,(case when a.MBH>40 then a.MBH-31 else MBH-30
end ) MBHdec
,(case when a.MBL>40 then a.MBL-31 else MBL-30
end ) MBLdec
from (
select i.NO
,to_number(regexp_replace(utl_raw.cast_to_raw(i.HEXS),'^([3|4][0-9])([3|4][0-9])$','\1')) MBH
,to_number(regexp_replace(utl_raw.cast_to_raw(i.HEXS),'^([3|4][0-9])([3|4][0-9])$','\2')) MBL
from HIDDEFS i
) a
) a) d
where 1=1
and c.NO=d.NO
))
--==============================================
,twokeys as (---以下がツーキーの定義
select * from (
select 'J' Ekey,'' skey,'1' entkey from dual
union select 'K' Ekey,'' skey,'2' entkey from dual
union select 'L' Ekey,'' skey,'3' entkey from dual
union select '-' Ekey,'' skey,'4' entkey from dual
union select '^' Ekey,'' skey,'5' entkey from dual
union select 'F1' Ekey,'' skey,'6' entkey from dual
union select 'F2' Ekey,'' skey,'7' entkey from dual
union select 'F3' Ekey,'' skey,'8' entkey from dual
union select 'F4' Ekey,'' skey,'9' entkey from dual
union select 'F5' Ekey,'' skey,'0' entkey from dual
union select 'Q' Ekey,'' skey,'UP' entkey from dual
union select 'W' Ekey,'' skey,'DOWN' entkey from dual
union select 'A' Ekey,'' skey,'LEFT' entkey from dual
union select 'S' Ekey,'' skey,'RIGHT' entkey from dual
union select 'F' Ekey,'' skey,';' entkey from dual
union select 'G' Ekey,'' skey,':' entkey from dual
union select 'H' Ekey,'' skey,'*' entkey from dual
union select 'V' Ekey,'' skey,'+' entkey from dual
union select 'B' Ekey,'' skey,'-' entkey from dual
union select 'N' Ekey,'' skey,'=' entkey from dual
union select 'Enter' Ekey,'' skey,'@' entkey from dual
union select 'T' Ekey,'' skey,'`' entkey from dual
union select 'R' Ekey,'' skey,'"' entkey from dual
union select 'E' Ekey,'' skey,'’' entkey from dual
union select 'Caps Lock' Ekey,'SHIFT' skey,'8' entkey from dual
union select 'Backspace' Ekey,'SHIFT' skey,'9' entkey from dual
))
--==============================================
select a.*
,'0xA5, 0x'||a.EHEX||', '
||'0x'||
(case
when a.SKEY = 'SHIFT' then '02'
else '00'
end)||', 0x'||a.SHEX||', 0x00, 0x00, 0x00,0x00 ' dats
from (
select
a.EKEY,a.SKEY,b.ENTKEY,a.KEYFACE,a.HID_CODE_DEC EDEC,a.HID_CODE_HEX EHEX
,b.HID_CODE_DEC SDEC,b.HID_CODE_HEX SHEX
from
(select b.* from (---ここではEKAYで最も一致と思われるHIDコード列の差分数を求めました
select
EKEY,min(diffs) duffs
from (
select
b.EKEY,b.SKEY,b.ENTKEY,a.KEYFACE,a.HID_CODE_DEC,a.HID_CODE_HEX
,length(a.keyface)-length(b.EKEY) diffs
from HIDFFSCODES a
,twokeys b
where 1=1
and instr(a.KEYFACE,b.EKEY)>0
and a.HID_CODE_DEC<256
and a.KEYFACE <> '-----'
)
group by EKEY
) a
,(select
b.EKEY,b.SKEY,b.ENTKEY,a.KEYFACE,a.HID_CODE_DEC,a.HID_CODE_HEX
,length(a.keyface)-length(b.EKEY) diffs
from HIDFFSCODES a
,twokeys b
) b
where 1=1
and a.EKEY=b.EKEY and a.DUFFS=b.DIFFS --差分数と
and instr(b.KEYFACE,a.EKEY)>0 --KEYの一致有無で、てほぼ一致の物をこれで求めました
) a
,(select b.* from (---ここではENTKEYで最も一致と思われるHIDコード列の差分数を求めました
select
ENTKEY,min(diffs) duffs
from (
select
b.ENTKEY,a.KEYFACE,a.HID_CODE_DEC,a.HID_CODE_HEX
,length(a.keyface)-length(b.ENTKEY) diffs
from HIDFFSCODES a
,twokeys b
where 1=1
and instr(a.KEYFACE,b.ENTKEY)>0
and a.HID_CODE_DEC<256
and a.KEYFACE <> '-----'
)
group by ENTKEY
) a
,(select
b.ENTKEY,a.KEYFACE,a.HID_CODE_DEC,a.HID_CODE_HEX
,length(a.keyface)-length(b.ENTKEY) diffs
from HIDFFSCODES a
,twokeys b
) b
where 1=1
and a.ENTKEY=b.ENTKEY and a.DUFFS=b.DIFFS --差分数と
and instr(b.KEYFACE,a.ENTKEY)>0 --KEYの一致有無で、てほぼ一致の物をこれで求めました
) b
where 1=1
and a.ENTKEY=b.ENTKEY
) a
order by a.EKEY


結果


rlt.csv

EKEY    SKEY    ENTKEY  KEYFACE EDEC    EHEX    SDEC    SHEX    DATS

- 4 - = 45 2D 61 3D 0xA5, 0x2D, 0x00, 0x3D, 0x00, 0x00, 0x00,0x00
B - B 5 05 45 2D 0xA5, 0x05, 0x00, 0x2D, 0x00, 0x00, 0x00,0x00
Backspace SHIFT 9 Backspace 42 2A 66 42 0xA5, 0x2A, 0x02, 0x42, 0x00, 0x00, 0x00,0x00
Backspace SHIFT 9 Backspace 42 2A 66 42 0xA5, 0x2A, 0x02, 0x42, 0x00, 0x00, 0x00,0x00
Caps Lock SHIFT 8 英数 Caps Lock 57 39 65 41 0xA5, 0x39, 0x02, 0x41, 0x00, 0x00, 0x00,0x00
Caps Lock SHIFT 8 英数 Caps Lock 57 39 65 41 0xA5, 0x39, 0x02, 0x41, 0x00, 0x00, 0x00,0x00
E ’ E 8 08 36 24 0xA5, 0x08, 0x00, 0x24, 0x00, 0x00, 0x00,0x00
Enter @ Enter 40 28 47 2F 0xA5, 0x28, 0x00, 0x2F, 0x00, 0x00, 0x00,0x00
F ; F 9 09 51 33 0xA5, 0x09, 0x00, 0x33, 0x00, 0x00, 0x00,0x00
F1 6 F1 58 3A 63 3F 0xA5, 0x3A, 0x00, 0x3F, 0x00, 0x00, 0x00,0x00
F2 7 F2 59 3B 64 40 0xA5, 0x3B, 0x00, 0x40, 0x00, 0x00, 0x00,0x00
F3 8 F3 60 3C 65 41 0xA5, 0x3C, 0x00, 0x41, 0x00, 0x00, 0x00,0x00
F3 8 F3 60 3C 65 41 0xA5, 0x3C, 0x00, 0x41, 0x00, 0x00, 0x00,0x00
F4 9 F4 61 3D 66 42 0xA5, 0x3D, 0x00, 0x42, 0x00, 0x00, 0x00,0x00
F4 9 F4 61 3D 66 42 0xA5, 0x3D, 0x00, 0x42, 0x00, 0x00, 0x00,0x00
F5 0 F5 62 3E 39 27 0xA5, 0x3E, 0x00, 0x27, 0x00, 0x00, 0x00,0x00
G : G 10 0A 52 34 0xA5, 0x0A, 0x00, 0x34, 0x00, 0x00, 0x00,0x00
H * H 11 0B 52 34 0xA5, 0x0B, 0x00, 0x34, 0x00, 0x00, 0x00,0x00
J 1 J 13 0D 58 3A 0xA5, 0x0D, 0x00, 0x3A, 0x00, 0x00, 0x00,0x00
K 2 K 14 0E 59 3B 0xA5, 0x0E, 0x00, 0x3B, 0x00, 0x00, 0x00,0x00
L 3 L 15 0F 60 3C 0xA5, 0x0F, 0x00, 0x3C, 0x00, 0x00, 0x00,0x00
N = N 17 11 45 2D 0xA5, 0x11, 0x00, 0x2D, 0x00, 0x00, 0x00,0x00
R " R 21 15 31 1F 0xA5, 0x15, 0x00, 0x1F, 0x00, 0x00, 0x00,0x00
T ` T 23 17 47 2F 0xA5, 0x17, 0x00, 0x2F, 0x00, 0x00, 0x00,0x00
V + V 25 19 51 33 0xA5, 0x19, 0x00, 0x33, 0x00, 0x00, 0x00,0x00
^ 5 ^ ~ 46 2E 62 3E 0xA5, 0x2E, 0x00, 0x3E, 0x00, 0x00, 0x00,0x00