cancel
Showing results for 
Search instead for 
Did you mean: 

Simulating Key Press

SOLVED
eykxas
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.

1 ACCEPTED SOLUTION

Accepted Solutions
tristaanogre
Community Hero

Re: Simulating Key Press

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);
  }
} 

Robert Martin
[Hall of Fame]
Please consider giving a Kudo if I write good stuff
----

Why automate?  I do automated testing because there's only so much a human being can do and remain healthy.  Sleep is a requirement.  So, while people sleep, automation that I create does what I've described above in order to make sure that nothing gets past the final defense of the testing group.
I love good food, good books, good friends, and good fun.

Mysterious Gremlin Master
Vegas Thrill Rider
Extensions available

View solution in original post

2 REPLIES 2
tristaanogre
Community Hero

Re: Simulating Key Press

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);
  }
} 

Robert Martin
[Hall of Fame]
Please consider giving a Kudo if I write good stuff
----

Why automate?  I do automated testing because there's only so much a human being can do and remain healthy.  Sleep is a requirement.  So, while people sleep, automation that I create does what I've described above in order to make sure that nothing gets past the final defense of the testing group.
I love good food, good books, good friends, and good fun.

Mysterious Gremlin Master
Vegas Thrill Rider
Extensions available

View solution in original post

eykxas
Contributor

Re: Simulating Key Press

Thank you, it works !

New Here?
Join us and watch the welcome video:
Announcements
Top Kudoed Authors