This code actually doesn't provide focus:
new Actions(driver).moveToElement(element).perform();
It provides a hover effect.
Additionally, the JS code .focus() requires that the window be active in order to work.
js.executeScript("element.focus();");
I have found that this code works:
element.sendKeys(Keys.SHIFT);
For my own code, I use both:
element.sendKeys(Keys.SHIFT);
js.executeScript("element.focus();");