(n00b) Switch ports on KVM

Status
Not open for further replies.

myk3

Member
I have an IOGear KVM and I am attempting to use a wireless keyboard and mouse through it. Everything works fine through the mouse port, but not through the keyboard port. I found a video online using a teensy to control this device, the same kvm as mine. I have a teensy from an old project that I never got around to doing and was wondering if I can control what happens when the button is pressed on the teensy. I only need to send the "scroll lock + scroll lock" button presses in order to switch the kvm.


I have no clue how to go about doing this and would appreciate anyone who can send me to the documentation needed to program this little guy.

The video I saw was here

https://www.youtube.com/watch?featur...&v=dgH07NEp1hg
 
Did he publish the code used in that video?

If not, you might ask the author if they'll give you the code. It's probably very simple, but having a copy of the already-tested code will make this much simpler.
 
Did he publish the code used in that video?

If not, you might ask the author if they'll give you the code. It's probably very simple, but having a copy of the already-tested code will make this much simpler.

No he didn't.. I sent him an email though, to see if he would share it..
 
If he doesn't release the code, you'll probably need to modify the Buttons example.

You can download Arduino and install Teensyduino, then open it within Arduino from File > Examples > Teensy > USB_Keyboard > Buttons. It's written for 10 buttons, but you can just connect 1 and not use the other 9. You'll probably just have to change the stuff the Keyboard.print() lines to send the right commands. This code is all free downloads, so you can take a look anytime and see if you feel comfortable with how the code works?
 
If he doesn't release the code, you'll probably need to modify the Buttons example.

You can download Arduino and install Teensyduino, then open it within Arduino from File > Examples > Teensy > USB_Keyboard > Buttons. It's written for 10 buttons, but you can just connect 1 and not use the other 9. You'll probably just have to change the stuff the Keyboard.print() lines to send the right commands. This code is all free downloads, so you can take a look anytime and see if you feel comfortable with how the code works?

He just sent me a link to the code.

Code:
// Sketch for Easy Button 
// 2012 Dave Jacoby <jacoby.david@gmail.com>

// This program for the Teensy takes a digital input on 10 (c7)
// and turns it into two Scroll Locks (ASCII 145), so I can use
// it as 

// Inspired by http://rasterweb.net/raster/2011/05/09/the-button/
// Not far divergent from sample code, with <10 lines of actual code
// so copyright? What copyright?

// ========= ========= ========= =========
void setup() {
  // make pin 10 an input and turn on the 
  // pullup resistor so it goes high unless
  // connected to ground:
  pinMode(10, INPUT_PULLUP);
  delay(2000);
  Keyboard.begin() ;
  }

// ========= ========= ========= =========
void loop() {
  if ( digitalRead( 10 ) == LOW ) {
    //Keyboard.write( 72 ); 
    //delay(300); 
    //Keyboard.write( 73 ); 
    //delay(300); 
    Keyboard.press( KEY_SCROLL_LOCK ) ;
    Keyboard.releaseAll() ;
    delay(300); 
    Keyboard.press( KEY_SCROLL_LOCK ) ;
    Keyboard.releaseAll() ;
    delay(600); // Delay of 6/10 second to keep from repeating.
    } 
  delay(10);
  }
 
Great. Just program that onto a Teensy 2.0 and it should work.

Get the software here:

http://www.pjrc.com/teensy/td_download.html

This tutorial shows more detail on how to use it:

http://www.pjrc.com/teensy/tutorial.html

Practice with getting the LED to blink at different speeds. Then when you are comfortable with how to program the board, program it with his code.

Before reassembling the Easy Button, or even before soldering wires, test to make sure it works be touching a wire between GND and pin 10.
 
Great. Just program that onto a Teensy 2.0 and it should work.

Get the software here:

http://www.pjrc.com/teensy/td_download.html

This tutorial shows more detail on how to use it:

http://www.pjrc.com/teensy/tutorial.html

Practice with getting the LED to blink at different speeds. Then when you are comfortable with how to program the board, program it with his code.

Before reassembling the Easy Button, or even before soldering wires, test to make sure it works be touching a wire between GND and pin 10.

Could i use the button on the teensy, instead of a easy button?
 
Great. Just program that onto a Teensy 2.0 and it should work.

Get the software here:

http://www.pjrc.com/teensy/td_download.html

This tutorial shows more detail on how to use it:

http://www.pjrc.com/teensy/tutorial.html

Practice with getting the LED to blink at different speeds. Then when you are comfortable with how to program the board, program it with his code.

Before reassembling the Easy Button, or even before soldering wires, test to make sure it works be touching a wire between GND and pin 10.

I downloaded the blink_slow and blink_fast, programmed it with the teensy loader. I then installed the arduino compiler and programmed the teensy using the code provided.. I had to switch it over to Keyboard, else the ide kept failing.. I am testing it by just bridging pin 10 and +5v, but nothing is happening.. Is there something else I should be doing?
 
Last edited:
I downloaded the blink_slow and blink_fast, programmed it with the teensy loader. I then installed the arduino compiler and programmed the teensy using the code provided.. I had to switch it over to Keyboard, else the ide kept failing.. I am testing it by just bridging pin 10 and +5v, but nothing is happening.. Is there something else I should be doing?

Well this is starting to get really fun..

I was able to get the scroll lock buttons to press.. i used the on screen keyboard in order to test it, but the KVM isn't switching the inputs..

I have tried compiling as a Keyboard + Mouse + Joystick and Serial + Keboard...
 
Last edited:
Here is the code I am currently using.. The KVM does not recognize the SL + SL keystrokes. I added the LED lightup so I could verify it was launching the loop when on the KVM, and it is. The KVM is jsut not recognizing the SL+SL

Code:
int ledPin = 11;

void setup(){
    pinMode(10, INPUT_PULLUP);
    delay(2000);
    Keyboard.begin();
}

void loop(){
    if (digitalRead(10) == LOW)
    {
      digitalWrite(ledPin, HIGH);
        Keyboard.press( KEY_SCROLL_LOCK ) ;
        Keyboard.releaseAll() ;
        delay(500);
        Keyboard.press( KEY_SCROLL_LOCK ) ;
        Keyboard.releaseAll() ;
        digitalWrite(ledPin, LOW);
    }
     delay(10);
}

EDIT: It switches the ports on my other KVM fine.. :(
 
Last edited:
Are both KVM switches the same brand/model? If not, can you double-press scroll-lock on a normal keyboard connected to the one that isn't working (to test whether double-scroll lock is actually the right key combination for that kvm). I've seen a few kvms that used a different key sequence to switch machines, so I'm just checking that the issue isn't due to sending the wrong key sequence on the non-working kvm.

Otherwise, I notice that you have modified the timing delays from the original code. The sampl code you posted would check for whether the button had been pressed every 10 ms (0.01 seconds). If it was pressed, it would then send 2 keypresses 300ms (0.3s) apart, then give you an additional 600ms (0.6 seconds) to let go of the button before starting the "is the button now pressed" checks again.

In your modified code, you have the same 10ms check interval, but you have increased the delay between the two keypresses to 500ms (0.5 seconds), and removed entirely the buffer time afterwards to let go of the button. The potential issues with this are that 0.5 seconds may be "too long" between keypresses for that kvm to recognise the pair as a "double-click", so that kvm may not then be joining the pair of keypresses together. The second issue is that if you take longer than 510ms to press-and-release your button (including the time it takes for the contacts inside the button to stop bouncing), your sequence of keystrokes will be sent twice. If the two kvms are the same, I'd be surprised if the delay changes would work on one and not the other though.

You can again test for double-click speed with a real keyboard plugged into the kvm - how much delay does it let you have before the real keyboard's double-press doesn't trigger the kvm into switching?

You should also be setting the pinMode for the led pin in setup, since you are using it:
pinMode(ledPin, OUTPUT);
 
Last edited:
Are both KVM switches the same brand/model? If not, can you double-press scroll-lock on a normal keyboard connected to the one that isn't working (to test whether double-scroll lock is actually the right key combination for that kvm). I've seen a few kvms that used a different key sequence to switch machines, so I'm just checking that the issue isn't due to sending the wrong key sequence on the non-working kvm.

Otherwise, I notice that you have modified the timing delays from the original code. The sampl code you posted would check for whether the button had been pressed every 10 ms (0.01 seconds). If it was pressed, it would then send 2 keypresses 300ms (0.3s) apart, then give you an additional 600ms (0.6 seconds) to let go of the button before starting the "is the button now pressed" checks again.

In your modified code, you have the same 10ms check interval, but you have increased the delay between the two keypresses to 500ms (0.5 seconds), and removed entirely the buffer time afterwards to let go of the button. The potential issues with this are that 0.5 seconds may be "too long" between keypresses for that kvm to recognise the pair as a "double-click", so that kvm may not then be joining the pair of keypresses together. The second issue is that if you take longer than 510ms to press-and-release your button (including the time it takes for the contacts inside the button to stop bouncing), your sequence of keystrokes will be sent twice. If the two kvms are the same, I'd be surprised if the delay changes would work on one and not the other though.

You can again test for double-click speed with a real keyboard plugged into the kvm - how much delay does it let you have before the real keyboard's double-press doesn't trigger the kvm into switching?

You should also be setting the pinMode for the led pin in setup, since you are using it:
pinMode(ledPin, OUTPUT);

The KVMs are not the same model / brand. I know the SL + SL key combo is the correct keystrokes since I have been using this KVM with a wired keyboard and mouse. I just switched to a wireless KB + Mouse combo, which only uses one USB dongle. This works great on the mouse side and not on the KB side; however, I can no longer change the port. I currently have a wired KB plugged into the KB side and just reaching over it and changing the input. This keyboard is tucked out of the way, so it doesn't look bad just want something different.

I tried the code I posted first, once I figured out how to compile and send the code to the teensy. After It didn't work I started messing with timing to see if that was the issue. I also don't have any buttons currently connected I am just bridging the wires to start the loop. Is this ok?

Thanks for letting me know about the pinMode, I just started messing with this today and learning as I go.
 
The KVMs are not the same model / brand. I know the SL + SL key combo is the correct keystrokes since I have been using this KVM with a wired keyboard and mouse. I just switched to a wireless KB + Mouse combo, which only uses one USB dongle. This works great on the mouse side and not on the KB side; however, I can no longer change the port. I currently have a wired KB plugged into the KB side and just reaching over it and changing the input. This keyboard is tucked out of the way, so it doesn't look bad just want something different.

I tried the code I posted first, once I figured out how to compile and send the code to the teensy. After It didn't work I started messing with timing to see if that was the issue. I also don't have any buttons currently connected I am just bridging the wires to start the loop. Is this ok?

Thanks for letting me know about the pinMode, I just started messing with this today and learning as I go.

Ok, given that I'd be testing with a shorter timing between keypresses rather than longer timing. I know for example that in Java, the default time interval between mouse-clicks to be detected as a "double click" is only 200ms. While the kvm won't itself be running Java, it's quite possible that it's using a similarly short "double-press" time interval.

Maybe try something like 60ms to 150ms delay between the two keypress events (and a longer delay after the two, because with that timing you'll end up with double-sends otherwise).

Other dumb question - did this kvm originally take a usb keyboard, or a PS/2 keyboard? If the kvm originally used a PS/2 keyboard, it may not actually understand USB itself (just passing through whatever comes along the USB port instead of actually reading the keyboard presses). If that is the case, it wouldn't matter what you sent via the USB keyboard - the kvm wouldn't understand it at all. You could still potentially use the teensy, but it'd be a more complex project (I *think* you'd need to add a PS/2 connector as another output from the teensy and plug that into the PS/2 port on the KVM, then send the PS/2 scan-codes through that connector - but it's not something I've done before so I'm not sure where you'd start with that/how to wire it up/etc).
 
Ok, given that I'd be testing with a shorter timing between keypresses rather than longer timing. I know for example that in Java, the default time interval between mouse-clicks to be detected as a "double click" is only 200ms. While the kvm won't itself be running Java, it's quite possible that it's using a similarly short "double-press" time interval.

Maybe try something like 60ms to 150ms delay between the two keypress events (and a longer delay after the two, because with that timing you'll end up with double-sends otherwise).

Other dumb question - did this kvm originally take a usb keyboard, or a PS/2 keyboard? If the kvm originally used a PS/2 keyboard, it may not actually understand USB itself (just passing through whatever comes along the USB port instead of actually reading the keyboard presses). If that is the case, it wouldn't matter what you sent via the USB keyboard - the kvm wouldn't understand it at all. You could still potentially use the teensy, but it'd be a more complex project (I *think* you'd need to add a PS/2 connector as another output from the teensy and plug that into the PS/2 port on the KVM, then send the PS/2 scan-codes through that connector - but it's not something I've done before so I'm not sure where you'd start with that/how to wire it up/etc).

Nope it is a USB KVM..

http://www.iogear.com/product/GCS632U/

The one that works is an older version of this one.. (actual version is a TK-409, which has since been discontinued)

http://www.trendnet.com/products/proddetail.asp?status=view&prod=230_TK-409K
 
Ok. I'm assuming you've connected the teensy to the Keyboard console port, with your wireless mouse/keyboard adaptor in the mouse console port (only the keyboard port on that kvm will respond to the switch-computers hotkeys).

I've had issues with key macros (which is essentially what you're using the Teensy to do) with some software in the past if there wasn't delays between the key pressed/key released events in the macro (software didn't recognise the keys were pressed at all, or joined the two presses together into one), and this kvm switch looks like it is pretty tempermental in what it actually recognises on the keyboard port (instead of being a "true" usb port, it does conversion of the USB information and then resends it as it's own usb-keyboard code - in part so that it can emulate keys that don't exist on the keyboard, etc). The Teensy does use the standard usb keyboard reports, so the kvm *should* be able to be read/interpret the teensy.

Try something like this, and let us know how it goes:
Code:
int ledPin = 11;

void setup(){
    pinMode(10, INPUT_PULLUP);
    pinMode(ledPin, OUTPUT);
    delay(2000);
    Keyboard.begin();
}

void loop(){
    if (digitalRead(10) == LOW)
    {
        digitalWrite(ledPin, HIGH);
        Keyboard.press( KEY_SCROLL_LOCK ) ;
        delay(50); // give time to recognise key down
        Keyboard.releaseAll() ;
        delay(150); // give time to recognise key up, so the next keypress is treated as a second press
        Keyboard.press( KEY_SCROLL_LOCK ) ;
        delay(50);
        Keyboard.releaseAll() ;
        delay(350); // give time to let go of button/wire connection before rescanning - may need increasing if you get multiple sends per press
        digitalWrite(ledPin, LOW);
    }
     delay(10);
}

Failing that, you could try toggling the setting for the kvm from scroll-lock+scroll-lock to ctrl+ctrl and modifying the code above to send CTRL key presses (replace the "Keyboard.press(KEY_SCROLL_LOCK);" with "Keyboard.set_modifier(MODIFIERKEY_CTRL); Keyboard.send_now();"). The FAQ on the iogear site (and the manual for the kvm) say how to toggle between using scroll lock or ctrl as the trigger: http://iogear.custhelp.com/app/answ...2LzEvdGltZS8xMzY4NTg2NDQyL3NpZC9vKkVQVmNxbA== . You'd need to use the wired keyboard to change between using scroll lock or ctrl as the triggers (and it looks like it's a toggle - so if it doesn't work you can toggle it back to scroll lock).
 
Ok. I'm assuming you've connected the teensy to the Keyboard console port, with your wireless mouse/keyboard adaptor in the mouse console port (only the keyboard port on that kvm will respond to the switch-computers hotkeys).

I've had issues with key macros (which is essentially what you're using the Teensy to do) with some software in the past if there wasn't delays between the key pressed/key released events in the macro (software didn't recognise the keys were pressed at all, or joined the two presses together into one), and this kvm switch looks like it is pretty tempermental in what it actually recognises on the keyboard port (instead of being a "true" usb port, it does conversion of the USB information and then resends it as it's own usb-keyboard code - in part so that it can emulate keys that don't exist on the keyboard, etc). The Teensy does use the standard usb keyboard reports, so the kvm *should* be able to be read/interpret the teensy.

Try something like this, and let us know how it goes:
Code:
int ledPin = 11;

void setup(){
    pinMode(10, INPUT_PULLUP);
    pinMode(ledPin, OUTPUT);
    delay(2000);
    Keyboard.begin();
}

void loop(){
    if (digitalRead(10) == LOW)
    {
        digitalWrite(ledPin, HIGH);
        Keyboard.press( KEY_SCROLL_LOCK ) ;
        delay(50); // give time to recognise key down
        Keyboard.releaseAll() ;
        delay(150); // give time to recognise key up, so the next keypress is treated as a second press
        Keyboard.press( KEY_SCROLL_LOCK ) ;
        delay(50);
        Keyboard.releaseAll() ;
        delay(350); // give time to let go of button/wire connection before rescanning - may need increasing if you get multiple sends per press
        digitalWrite(ledPin, LOW);
    }
     delay(10);
}

Failing that, you could try toggling the setting for the kvm from scroll-lock+scroll-lock to ctrl+ctrl and modifying the code above to send CTRL key presses (replace the "Keyboard.press(KEY_SCROLL_LOCK);" with "Keyboard.set_modifier(MODIFIERKEY_CTRL); Keyboard.send_now();"). The FAQ on the iogear site (and the manual for the kvm) say how to toggle between using scroll lock or ctrl as the trigger: http://iogear.custhelp.com/app/answ...2LzEvdGltZS8xMzY4NTg2NDQyL3NpZC9vKkVQVmNxbA== . You'd need to use the wired keyboard to change between using scroll lock or ctrl as the triggers (and it looks like it's a toggle - so if it doesn't work you can toggle it back to scroll lock).

When i first started this adventure I was able to change the hotkey from SL to CTRL.. I changed it back since I had no use at the time.. I will test this tomorrow.. Thanks for the help..
 
Well I still can't get any combination working. I tried the posted code, changing it to CTRL + CTRL (on the KVM and the code) and that didn't work. I tried the original code again, and it still isn't working..

I know this is probably a stupid question but I am compiling as "keyboard + Mouse + Joystick". I am also using Arduion version 1.0.3, since the teensy installer said my folder for 1.0.4 was not valid. Is this ok?
 
Last edited:
Well I still can't get any combination working. I tried the posted code, changing it to CTRL + CTRL (on the KVM and the code) and that didn't work. I tried the original code again, and it still isn't working..

I know this is probably a stupid question but I am compiling as "keyboard + Mouse + Joystick". I am also using Arduion version 1.0.3, since the teensy installer said my folder for 1.0.4 was not valid. Is this ok?

the worst part is the trendnet switches fine, but for some odd reason when i have the dvi port used on my laptop it doesn't detect the VGA, only when using the trendnet, it works fine on the iogear
 
Keyboard/Mouse/Joystick or Serial/Keyboard/Mouse/Joystick should both work...if the KVM were doing the right thing (and I haven't screwed up something stupid in the code).

I'm running out of ideas for this :(. It's sounding a lot like the KVM isn't properly reading the keyboard data reports (despite them being the normal standard "bios-mode" USB keyboard report). Is it at least passing the data through to the currently-connected computer?

If you change the programming so that it sends a normal keypress (e.g. send KEY_A twice instead of sending KEY_SCROLL_LOCK twice), and then open a text document, does the computer type that letter twice into the document when you make the touch connection while the teensy is plugged into the keyboard port of the KVM? Does it type that letter twice when the teensy is plugged directly into one of the computer's usb ports (not through the kvm)? If they both type the double-a, then I'm at a total loss - it would mean (if I've read the manual/faqs for that kvm switch right) that the kvm understood the teensy usb keyboard presses well enough to emulate them but not to actually respond to them (wtf?). If the computer typed the a, but the kvm didn't, then the kvm is probably not recognising the teensy USB keyboard at all. If neither typed it, then there's a problem with the actual sending code so that the keypresses are not actually being sent.

If it's working through the computer but not through the kvm, the last thing I can think of to try is more difficult - it would be to change the teensy hardware-library code so that it *only* reported the Keyboard USB HID interface (in case it was the presence of the mouse/joystick interfaces that is causing the KVM's emulation to go wacky), and not the mouse/joystick/(Serial) interfaces. Paul is probably a *much* better person to describe how to cut that down properly - there's a lot of stuff in there, and if you get it wrong the computer won't recognise the teensy when you boot your code (though you can at least get it back into reprogram mode by holding down the reset button on the teensy while plugging it into the computer if that happens).
 
Just my 2c here - if you are having trouble with an Iogear KVM not recognizing a composite device through its keyboard port, the problem is the Iogear, not your device.

I ran into this exact problem years ago on a 4-port Iogear KVM. I detailed my problems here: http://rewiredgear.net/deckmod5.html (about half way down). Composite device would work fine connected directly to computer, but not on the Iogear. The Iogear would not recognize anything except a simple keyboard.

My solution now, run virtual machines and ditch the KVM.
 
Keyboard/Mouse/Joystick or Serial/Keyboard/Mouse/Joystick should both work...if the KVM were doing the right thing (and I haven't screwed up something stupid in the code).

I'm running out of ideas for this :(. It's sounding a lot like the KVM isn't properly reading the keyboard data reports (despite them being the normal standard "bios-mode" USB keyboard report). Is it at least passing the data through to the currently-connected computer?

If you change the programming so that it sends a normal keypress (e.g. send KEY_A twice instead of sending KEY_SCROLL_LOCK twice), and then open a text document, does the computer type that letter twice into the document when you make the touch connection while the teensy is plugged into the keyboard port of the KVM? Does it type that letter twice when the teensy is plugged directly into one of the computer's usb ports (not through the kvm)? If they both type the double-a, then I'm at a total loss - it would mean (if I've read the manual/faqs for that kvm switch right) that the kvm understood the teensy usb keyboard presses well enough to emulate them but not to actually respond to them (wtf?). If the computer typed the a, but the kvm didn't, then the kvm is probably not recognising the teensy USB keyboard at all. If neither typed it, then there's a problem with the actual sending code so that the keypresses are not actually being sent.

If it's working through the computer but not through the kvm, the last thing I can think of to try is more difficult - it would be to change the teensy hardware-library code so that it *only* reported the Keyboard USB HID interface (in case it was the presence of the mouse/joystick interfaces that is causing the KVM's emulation to go wacky), and not the mouse/joystick/(Serial) interfaces. Paul is probably a *much* better person to describe how to cut that down properly - there's a lot of stuff in there, and if you get it wrong the computer won't recognise the teensy when you boot your code (though you can at least get it back into reprogram mode by holding down the reset button on the teensy while plugging it into the computer if that happens).


It is working through the computer.. I used this video to build an "awesome" button, but just bridging the wires.

How do I go about attempting to make this only a keyboard and not a Joystick etc..
 
I would use a VM, but the machines on the KVM are on different networks.. I guess i could add an extra network card though..
 
Last edited:
Can i configure the teensy just a a keyboard and nothing else?

Yes, but you'll have to edit the USB code. The code is a bit complex, but just disabling the stuff you don't want is relatively easy.

The code for Teensy 2.0 and 3.0 is different, so any more specific answer depends on which board you're using.
 
Yes, but you'll have to edit the USB code. The code is a bit complex, but just disabling the stuff you don't want is relatively easy.

The code for Teensy 2.0 and 3.0 is different, so any more specific answer depends on which board you're using.


I am using a Teensy 2.0
 
Status
Not open for further replies.
Back
Top