eykxas
8 years agoRegular Contributor
Simulating Key Press
Hi,
I have a little problem. I want to simulate key press with Low Level.
I have this code :
function test(value){ var i = 0; for (;i < value.length; i++){ var chrK = value.charCodeAt(i); LLPlayer.KeyDown(VK_SHIFT, 200); LLPlayer.KeyDown(chrK, 200); LLPlayer.KeyUp(chrK, 200); LLPlayer.KeyUp(VK_SHIFT, 200); } }
This code work perfectly. But when I remove the Shift press (for write the string in lower case), the method LLPlayer.KeyDown write the wrong character.
For exemple, if value is set with "A" the function simulate Shift + A perfectly. But if value is set with "a" the function simulate "1".
the charCode "A" is 65
the charCode "a" is 97.
but it return "1".
I need help to solve this issue.
That's because the KeyDown and KeyUp commands don't take the ASCII character string but the VK Code for the ascii character. You need to call a Win32API method to get this to really work properly. Something like
function testlp(value){ var i; for (i = 0; i < value.length; i++){ var chrK = Win32API.VkKeyScan(value[i]); LLPlayer.KeyDown(VK_SHIFT, 200); LLPlayer.KeyDown(chrK, 200); LLPlayer.KeyUp(chrK, 200); LLPlayer.KeyUp(VK_SHIFT, 200); } }