XT/AT/PS2/Terminal to USB Converter with NKRO

User avatar
bhtooefr

08 Jul 2013, 01:11

Oh, good to know. I'll need to fix that if I ever convert to ANSI.

User avatar
Halvar

08 Jul 2013, 07:46

Thank you!

User avatar
Muirium
µ

10 Jul 2013, 01:54

Two sockets wired in parallel does indeed work quite nicely. I've been using my XT for a week now, and now I have a couple of PS/2 keyboards in on the USB action too. Nice!

I have a question about each one of them.

The first is a Microsoft Natural Multimedia (ergonomic) keyboard. (It's nothing great, but I'm experimenting with the shape.) By default, its function row is mapped to all sorts of media keys. Here's a quick list of F1 through F12:
  • Help
  • Undo
  • Redo
  • New
  • Open
  • Close
  • Reply
  • Forward
  • Send
  • Spell
  • Save
  • Print


Only some of these are available as codes in the docs. But all these keys do send events, according to hid_listen. Can I find their hex code that way and enter it into my .sc file?

The second keyboard is an Acer 6312 (clicky membrane!) which precedes the invention of Windows keys. Alt and Alt Gr sit neatly either side of the space bar and I suppose I could just use one of them for Command (GUI) and the other for Option (ALT) but I'm so used to a Command at both sides I'd rather not. Ditto for Control, both of which are where they should be. I don't know how to tell whether any given keyboard has GUI keys or not, anyway, so I thought of using combinations. How about pressing both left and right Command keys (the alts) to get an Option? (This is a simplified example, as I hit Command+Option shortcuts way more often than Option-only ones.)

Code: Select all

# Command + Command = Option (for Windows-keyless PS/2 keyboards)
macro lalt ralt
push_meta set_meta ralt
press << what exactly? >>
pop_meta
endmacro
Obviously, omitting the press statement entirely results in bugger all actually happening. (So obvious that I did indeed test it myself.) Making modifier-only macros is beyond the scope of the current converter, I assume? Certainly, I don't know how to issue the command.

Also, the Acer's lock LEDs seem to be half lit the whole time. They do glower, good and angry, when I exceed the keyboard's lame rollover, however.

Aaand lastly, both of these PS/2 keyboards show up as Keyboard ID: AB83. Hmm?

User avatar
Soarer

10 Jul 2013, 02:17

There's probably quite a few PS/2 keyboards that send non-standard codes... and in most cases would have a driver loaded into the OS to catch them. I'm not sure how I might handle those yet, since there's potentially a lot of them a simple table might not be sufficient. If you could list the codes it would give me something to think about... :)

Maybe something like this (untested) for Command keys...

Code: Select all

# pressing lalt with ralt already held...
macro lalt ralt
push_meta clear_meta ralt
set_meta lgui
onbreak norestoremeta
pop_meta
endmacro

# pressing ralt with lalt already held...
macro ralt lalt
push_meta clear_meta lalt
set_meta rgui
onbreak norestoremeta
pop_meta
endmacro
With those you should be able to 'roll' over the combo... so you could press ralt down, lalt down, release ralt, and then still have lgui active when you press other keys, until you release lalt.

Or, if you want to do Command+Option combos easily, maybe take the clear_meta out of one of them.

AB83 is what nearly all 101/102 etc key PS/2 keyboards return.
Last edited by Soarer on 10 Jul 2013, 13:25, edited 2 times in total.

User avatar
Muirium
µ

10 Jul 2013, 02:32

Sweet stuff! That'll be a real help in trying out more advanced features than I've managed.

Here's the Microsoft ergo's weird-ass function row keys, pressed slowly and in order from F1-F12 again, according to hid_listen:

Code: Select all

Waiting for device:
Listening:
rE0 r05 +00 
r05 -00 
r3D +00 
rE0 rF0 r3D -00 
rE0 r36 +00 
rE0 rF0 r36 -00 
rE0 r0C +00 
rE0 rF0 r0C -00 
rE0 r03 +00 
rE0 rF0 r03 -00 
rE0 r0B +00 
rE0 rF0 r0B -00 
rE0 r83 +00 
rE0 rF0 r83 -00 
rE0 r0A +00 
rE0 rF0 r0A -00 
rE0 r01 +00 
rE0 rF0 r01 -00 
r33 +00 
rE0 rF0 r33 -00 
rE0 r78 +00 
rE0 rF0 r78 -00 
rE0 r07 +00 
rE0 rF0 r07 -00 
Each press / release sends a line, but they aren't the dxx and uxx codes I was looking for.

User avatar
Muirium
µ

10 Jul 2013, 02:48

Code: Select all

on_break norestoremeta
is giving me an invalid argument error in scas,

Also: it's that late!? You got me staying up playing with keyboards again! (Thanks.)

User avatar
Soarer

10 Jul 2013, 02:52

Thanks for the codes :D

Oops... try onbreak instead, like it says in the docs... I should RTFM before posting! :lol:

User avatar
Muirium
µ

11 Jul 2013, 00:47

With that change, it now works quite nicely. Thanks! Of course, the Acer's low bloody rollover kicks in right when I try to press arrow keys (for Option+Arrow word by word navigation) but that's its fault. I can now üse ümlauts again, hurrah.

So here's my entire config, getting ever longer and to be eventually split once I've worked out the overall logic:

Code: Select all

# define that FN1 accesses layer 1
layerblock
	FN1 		1
	FN2 		1
	FN1 FN2		1
endblock


###				XT


# Base layer remaps time
# need to map the FN key into the base layer (0)
remapblock
# Just for the PC/XT keyboard
ifset set1
layer 0
	PAD_ASTERIX FN1					# The all important function key
	LCTRL		FN1					# And the second one: currently the same
	PAD_PLUS 	PAD_ENTER			# Puts an enter at the far right edge
	LALT 		LGUI				# Command!
	CAPS_LOCK 	RGUI				# And again
	PAD_0 		RALT				# Option spills over onto the numpad
	PAD_PERIOD	RCTRL				# Control does too
	F9 			LCTRL				# Mirror image for left and function keys
	F10			LALT				# Completing the 6 mod set
	SCROLL_LOCK SYSTEM_POWER		# Closest I got to Eject, works nicely
	PAD_1 		END					# Hijack the numpad for cursor controls
	PAD_2 		DOWN
	PAD_3 		PAGE_DOWN
	PAD_4 		LEFT
	PAD_5 		UNASSIGNED
	PAD_6 		RIGHT
	PAD_7 		HOME
	PAD_8 		UP
	PAD_9 		PAGE_UP
	F1 			MEDIA_VOLUME_DOWN	# Hijack the f-keys for media controls
	F2 			MEDIA_VOLUME_UP
	F3 			MEDIA_MUTE
	F4 			MEDIA_PLAY_PAUSE
	F5 			F9					# Including the full set for Exposé
	F6 			F10
	F7 			F11
	F8 			F12
endblock


# Primary Function Layer: HHKB + ESDF Arrows
# the layer itself is just some remaps tagged with the layer number
remapblock
# Just for the PC/XT keyboard
ifset set1
layer 1
# 	HHKB Arrows
	LEFT_BRACE 	UP
	SEMICOLON 	LEFT
	SLASH 		DOWN
	QUOTE 		RIGHT
	L 			PAGE_UP
	PERIOD 		PAGE_DOWN
	K 			HOME
	COMMA 		END
	H 			PAD_ASTERIX
	J 			PAD_SLASH
	N			PAD_PLUS
	M			PAD_MINUS
	
# 	ESDF Arrows	
	E			UP
	S			LEFT
	D			DOWN
	F			RIGHT
	R			PAGE_UP
	V			PAGE_DOWN
	A			HOME
	G			END
	
# 	Restore the Numpad	
	PAD_1		PAD_1
	PAD_2		PAD_2
	PAD_3		PAD_3
	PAD_4		PAD_4
	PAD_5		PAD_5
	PAD_6		PAD_6
	PAD_7		PAD_7
	PAD_8		PAD_8
	PAD_9		PAD_9
	PAD_PLUS	PAD_PLUS
	PAD_PERIOD	PAD_PERIOD
	PAD_0		PAD_0
	
# 	Restore the Function Keys	
	F1			F1
	F2			F2
	F3			F3
	F4			F4
	F5			F5
	F6			F6
	F7			F7
	F8			F8
	F9			F9
	F10			F10
	
# 	Media keys across the number row	
	1			F14					# Decrease Display Brightness 
	2			F15					# Increase Display Brightness
	3			F10					# Exposé: All App Windows
	4			F12					# Dashboard
	5			F11					# Exposé: Show Desktop
	6			F9					# Exposé: All Windows in All Apps
	7			MEDIA_PREV_TRACK	# iTunes / media playback controls
	8			MEDIA_PLAY_PAUSE
	9			MEDIA_NEXT_TRACK
	0			MEDIA_MUTE			# Volume controls
	MINUS		MEDIA_VOLUME_DOWN
	EQUAL		MEDIA_VOLUME_UP
	BACKSPACE	DELETE				# Delete for Backspace
	LCTRL		CAPS_LOCK			# Capslock lives, out of harm's way
	ENTER		PAD_ENTER			# Enter for Return
	ESC			EUROPE_2			# This § symbol
	BACK_QUOTE	EUROPE_2			# In both places I might look for it
endblock


# Let the going get weird
# Match the PC/XT's unusual legends
# Just for the PC/XT keyboard
ifset set1
macroblock

# Shift 2 = "
macro 2 shift -ctrl -alt -gui
press QUOTE
endmacro

# Shift ' = @
macro QUOTE shift -ctrl -alt -gui
push_meta set_meta lshift
press 2
pop_meta
endmacro

# Shift Option + # = ±
# Corresponding with § remap, this time with shift
macro BACK_QUOTE shift alt -gui -ctrl
push_meta set_meta rshift
press EUROPE_2
pop_meta
endmacro

# ` = #
macro BACK_QUOTE -all
push_meta set_meta ralt
press 3
pop_meta
endmacro

# Command + Escape = Command + Section break (for app window cycling)
macro ESC gui -ctrl -alt
press EUROPE_2
endmacro

# Num Lock = Ctrl + Cmd + Opt + 8 (Negative / night colours mode)
macro num_lock
push_meta set_meta rgui ralt rctrl
press 8
pop_meta
endmacro

endblock


###				PS/2



# Base layer remaps time
remapblock
# For generic PS/2 keyboards
ifset set2ext
layer 0
	CAPS_LOCK 	FN1					# The all important function key
	LGUI		LALT				# Rejangle PC keys into Mac mods
	LALT		LGUI
	RALT		RGUI
	MENU		RALT				# Including the many faces of the "menu key"
	APP			RALT
	RGUI		RALT
	
#	Function Row Media keys	
	F1			F14					# Decrease Display Brightness
	HELP		F14					# Ditto for media keyboards
	F2			F15					# Increase Display Brightness
	UNDO		F15
	F3			F10					# Exposé: All App Windows
	AGAIN		F10					# Redo?
	F4			F12					# Dashboard
#	NEW			F12
	F5			F11					# Exposé: Show Desktop
#	OPEN		F11
	# F6		F9					# Exposé: All Windows in All Apps
	# CLOSE		F9
	F6			MEDIA_PREV_TRACK	# iTunes / media playback controls
#	CLOSE		MEDIA_PREV_TRACK	# Which map to funky keys on the ergo
	F7			MEDIA_PLAY_PAUSE
#	REPLY		MEDIA_PLAY_PAUSE
	F8			MEDIA_NEXT_TRACK
#	FWD			MEDIA_NEXT_TRACK
	F10			MEDIA_MUTE			# Volume controls
#	SPELL		MEDIA_MUTE
	F11			MEDIA_VOLUME_DOWN
#	SAVE		MEDIA_VOLUME_DOWN
	F12			MEDIA_VOLUME_UP
#	PRINT		MEDIA_VOLUME_UP
	
endblock

# Primary Function Layer: HHKB + ESDF Arrows
# Generic PS/2 keyboards
ifset set2ext
remapblock
layer 1
# 	HHKB Arrows
	LEFT_BRACE 	UP
	SEMICOLON 	LEFT
	SLASH 		DOWN
	QUOTE 		RIGHT
	L 			PAGE_UP
	PERIOD 		PAGE_DOWN
	K 			HOME
	COMMA 		END
	H 			PAD_ASTERIX
	J 			PAD_SLASH
	N			PAD_PLUS
	M			PAD_MINUS
	
# 	ESDF Arrows	
	E			UP
	S			LEFT
	D			DOWN
	F			RIGHT
	R			PAGE_UP
	V			PAGE_DOWN
	A			HOME
	G			END

# 	Media keys across the number row	
	1			F14					# Decrease Display Brightness 
	2			F15					# Increase Display Brightness
	3			F10					# Exposé: All App Windows
	4			F12					# Dashboard
	5			F11					# Exposé: Show Desktop
	6			F9					# Exposé: All Windows in All Apps
	7			MEDIA_PREV_TRACK	# iTunes / media playback controls
	8			MEDIA_PLAY_PAUSE
	9			MEDIA_NEXT_TRACK
	0			MEDIA_MUTE			# Volume controls
	MINUS		MEDIA_VOLUME_DOWN
	EQUAL		MEDIA_VOLUME_UP
	BACKSPACE	DELETE				# Delete for Backspace
	LCTRL		CAPS_LOCK			# Capslock lives, out of harm's way
	ENTER		PAD_ENTER			# Enter for Return
	ESC			EUROPE_2			# This § symbol

# 	Restore the Function Keys	
	F1			F1
	F2			F2
	F3			F3
	F4			F4
	F5			F5
	F6			F6
	F7			F7
	F8			F8
	F9			F9
	F10			F10
	
#	In case of missing mods: here's the numpad
	PAD_0		RGUI
	PAD_PERIOD	RALT
	PAD_ENTER	RCTRL

endblock

# Macro time
# For generic PS/2 keyboards
ifset set2ext
macroblock

# Command + ` = Command + Section break (for app window cycling)
macro BACK_QUOTE gui -ctrl -alt
press EUROPE_2
endmacro

# Num Lock = Ctrl + Cmd + Opt + 8 (Negative / night colours mode)
macro num_lock
push_meta set_meta rgui ralt rctrl
press 8
pop_meta
endmacro

# Soarer's sneaky rollover modifiers for Winkeyless keyboards
# To get Option by itself: press and hold Right Alt then Left Alt
macro lgui rgui
clear_meta rgui
push_meta clear_meta gui
set_meta lalt
onbreak norestoremeta
pop_meta
endmacro

# To get Command + Option: press and hold Left Alt then Right Alt
macro rgui lgui
clear_meta lgui
push_meta set_meta ralt rgui
onbreak norestoremeta
pop_meta
endmacro

endblock
Includes a handful of tricks for keyboards without all the modern modifiers. Said Alt+Alt technique to get Option with or without Command, and a simple backup where the usual three keys at the bottom of the numpad are reassigned in the function layer.

Still only one function layer. I planned more. But much of my sleight of hand is yet to be figured out in practice.

User avatar
Soarer

11 Jul 2013, 02:13

So that rollover thing works OK on other boards, just not that one? Bummer if so, it must be one that assumes you'll never want to press both the left and right of some modifier (and something else as well) at the same time :(

I think the only time I've used a macro triggered only on modifiers is to use both shifts to press capslock, a much simpler case :)

User avatar
Muirium
µ

11 Jul 2013, 18:49

Shift + Shift = Caps Lock? It's so obvious! I must steal that one.

Believe it or not, I only have two PS/2 keyboards kicking around to test with. (Never used to have anything to hook them up to.) The Acer is definitely a bugger for its lack of mods and the decency to behave itself while faking more of them, but it is clicky and white dyesub PBT, so it's almost nice.

I'm on the Microsoft ergo just now and can confirm that with even its miserable 4 or 5KRO, the Alt + Alt Gr = Option trick works and word based arrow navigation is possible. With one catch! Unbelievably, left arrow doesn't show up when doing that! Up, down, and right are all just fine. They're both out to get me! Oh well, at least it has enough native mods anyway.

I'm getting some jammed Command key(s) too, typically after hitting Command + Tab, Tab, Tab, and releasing Command at the end, for app switching. That happened quite a bit while I had my XT hooked up to my 10 year old PowerBook (on USB 1.1). I saw the Teensy's onboard light was constantly lit, too, but otherwise things were working.

User avatar
Muirium
µ

11 Jul 2013, 21:12

This is what my converter actually looks like, for now:
IMG_6815.JPG
IMG_6815.JPG (110.74 KiB) Viewed 11368 times
Looking into making it a nice little aluminium box while Matt3o's got the laser busy. I'm so going to tug this thing apart if I don't protect it!

User avatar
Soarer

12 Jul 2013, 03:08

Steal away!

Code: Select all

macro lshift rshift
press caps_lock
endmacro
macro rshift lshift
press caps_lock
endmacro
I used that trick in Autohotkey before my converter existed...

Code: Select all

Lshift & Rshift::SetCapsLockState, % GetKeyState("CapsLock", "T")? "Off":"On"
Rshift & Lshift::SetCapsLockState, % GetKeyState("CapsLock", "T")? "Off":"On"
... can't remember where I stole it from :lol:

The 2KRO boards will fail on some of these combos I suppose :(

But the XT should be fine?! Not sure why that gets jammed, or why the LED is lit all the time :( The two things are probably related somehow - I wonder if hid_listen has any output that would help diagnose it...

User avatar
Muirium
µ

12 Jul 2013, 03:19

I'll give it closer inspection next time it shows up. My PowerBook is good at triggering it, but runs Tiger (10.4), which is too old a version of OS X to successfully compile hid_listen for!

(I recompiled your tools as well as PJRC's hid_listen for PowerPC on my G5. They work flawlessly in Leopard (10.5), hurrah! And compile for 10.4 if I hack around the make script a bit; but they rely on things 10.4 just doesn't have and they fail to run. So no dice on the old PowerBook. Yes: I like my old computers as well as old keyboards!)

By the way, to upload future versions of your converter, would I need physical access to the Teensy 2's reset button? It's time I put it in an enclosure. I already had to resolder a failed joint today! Life's dangerous when your wires are exposed.

Another pie in the sky feature request: it'd be super useful if the converter knew if it was connected to a Mac, Windows, or Linux. My Mac-centric remappings cause all kinds of confusion when tested on a regular PC. Just like you'd expect!

User avatar
bhtooefr

12 Jul 2013, 03:34

scboot will reboot the converter into the bootloader (equivalent to pushing the button).

User avatar
Muirium
µ

12 Jul 2013, 03:36

Aha! I hoped as much, cheers!

User avatar
Soarer

12 Jul 2013, 03:56

Ah, 10.4, OK.

There's no way to tell what OS it's connected to... you'll have to tell it by using ifselect etc. ;)

User avatar
Muirium
µ

12 Jul 2013, 04:08

ENGAGE_PC_MODE!

User avatar
Muirium
µ

21 Jul 2013, 03:25

Any chance of layer specific macros? I'm looking to keep the layers as logical as I can.

User avatar
Soarer

21 Jul 2013, 03:36

There will be more macro trigger stuff in the next release, but I'm not sure when that will be...

If you don't need loads of them, just remap keys in the layer to unused HID codes and then trigger macros from them!

User avatar
Muirium
µ

21 Jul 2013, 04:07

Sneaky as always! I like it.

andrewjoy

24 Jul 2013, 15:33

Hello, I have built this converter and the programming is fine as far as i can tell, but i am having problems getting my 122 key model f to work.

I think the problem is in the dip switch settings but i am also wondering if there is something wrong with my electronics too possibly not getting a clean clock ect.

I simply cannot get the converter detect the scan code of the keyboard it always detects it as scanset 1. I have sent a config file to the converter to force it into scancode set 3 this does work but the keyboard still does not return anything, most of the time. I connected it like this once or twice and it was returning something with each key press but it returned the error code for each key press nothing was repeating and i did look like it was registering the keys correctly but it was jsut not sending any scancodes.

Does anyone else with a terminal model f know what the dip switches do or how to set them. ( will get more info on the exact model of the F when i get home.

I was thinking of buying a scope next month for some other projects was wondering if i could use this to capture what the keyboard is sending down the data line if anything at all.

User avatar
Muirium
µ

24 Jul 2013, 18:01

And another puzzle for you, Soarer:
Image
Any idea to how to approach IBM 5291-2?

I also have a Hall Effect keyboard waiting as a challenge for another day!

User avatar
Soarer

24 Jul 2013, 18:48

andrewjoy wrote:I simply cannot get the converter detect the scan code of the keyboard it always detects it as scanset 1. I have sent a config file to the converter to force it into scancode set 3 this does work but the keyboard still does not return anything, most of the time. I connected it like this once or twice and it was returning something with each key press but it returned the error code for each key press nothing was repeating and i did look like it was registering the keys correctly but it was jsut not sending any scancodes.
What error codes are you getting in hid_listen?
andrewjoy wrote:Does anyone else with a terminal model f know what the dip switches do or how to set them. ( will get more info on the exact model of the F when i get home.
The DIP switches set the Keyboard's ID. But since the converter will never choose to use set 1 if it reads an ID, they aren't the problem.
andrewjoy wrote:I was thinking of buying a scope next month for some other projects was wondering if i could use this to capture what the keyboard is sending down the data line if anything at all.
You could try my Simple Logic Analyzer :ugeek:

andrewjoy

24 Jul 2013, 20:15

I was convinced it was my piss poor wiring so i went to rewire the teensy and managed to lift the contacts to ground and the clock and data lines

looks like i will have to buy another and this time not try to solder it with an iorn that's A too hot and B not use crappy lead free solder

i will be back thanks for your time , hopefully it will work better

User avatar
Soarer

24 Jul 2013, 23:42

Oops! Not sure how thick the wires you used were, but if they fill the hole up too snugly it can be harder to desolder them :(

There is another ground connection, and this hex uses different pins: PD2 for data, and PD3 for clock.

I'm guessing you have a Teensy 2.0...?
Soarer_at2usb_v1.12_atmega32u4_PD2data_PD3clock.zip
(15.62 KiB) Downloaded 201 times

andrewjoy

25 Jul 2013, 09:57

You sir are a legend thank you, going to pick up some thinner wire today ( that's what i get for salvaging wire out of old power supply's :P) and some decent 60/40 and test tonight.

Cannot wait to get this working,

Just need to think of a way to fix one of the keyboard stabilizers now :)

User avatar
Muirium
µ

25 Jul 2013, 17:39

Hey Soarer, should I include the mysterious 5th wire (PE) in the converter I am building for Tom?
Image
I'm using a choc block this time so he can put on different sockets eventually. Does the 5th line actually do anything?

User avatar
Soarer

25 Jul 2013, 21:46

If you do, then wire it to ground. It connects only to the shield on the cable, which in some cases is also connected to the GND wire at the keyboard end. It's fine left unconnected in converters.

User avatar
Muirium
µ

25 Jul 2013, 21:51

Phew, because I finished the job without it anyway!
Image
Now with built in modularity for socket swapping. Guess where the RJ45 socket came from…

User avatar
Muirium
µ

27 Jul 2013, 23:53

As always, this might be a dumb question.

Can you "else" the ifs? The more PS/2 keyboards I use, the cunninger my logic is needing to be. Right now I can't seem to limit only one set of remaps to be put in action unless I have a whole separate keyboard ID for each piece of hardware. Alas, I do not. But else statements could get me there. (Or so I think until experience proves otherwise.)

Post Reply

Return to “Workshop”