browser sendkey

883 views
Skip to first unread message

cool_...@hotmail.com

unread,
Feb 12, 2013, 3:18:53 PM2/12/13
to cefp...@googlegroups.com
Hi

im trying to use sendkey to browser and i need to simulate that the shift key is down programmely, but i can't get it to work!

here is the code:
self.browser.SendKeyEvent(cefpython.KEYTYPE_KEYDOWN,self.keyInfo(cefpython.VK_TAB),cefpython.KEY_SHIFT)

I have also tried adding following code before the tab send key, withou luck:
self.browser.SendKeyEvent(cefpython.KEYTYPE_KEYDOWN,self.keyInfo(cefpython.VK_LSHIFT),0)

what im trying to get the code to do, is tab down when i press the down arrow on the keyboard, and then i want it to tab back up when the up key is pressed!

help please, how do this?

cheers
c_bb

Czarek Tomczak

unread,
Feb 12, 2013, 3:52:05 PM2/12/13
to cefp...@googlegroups.com
Hi c_bb,

Did you try with other keys? For example "shift+a" in a textarea?

Try also this:

    SendKeyEvent(cefpython.KEYTYPE_KEYDOWN, (cefpython.VK_TAB, false, false), cefpython.VK_LSHIFT);

Try a combination of (cefpython.VK_TAB, false, false) / (cefpython.VK_TAB, false, true) 
with both KEY_SHIFT & VK_LSHIFT.

Cheers,
Czarek.

Czarek Tomczak

unread,
Feb 12, 2013, 4:02:00 PM2/12/13
to cefp...@googlegroups.com
"modifiers" parameter in SendKeyEvent() is an LPARAM in WM_KEYDOWN message:

Using cefpython.KEY_SHIFT is probably wrong, these constant is for use only with
KeyboardHandler.OnKeyEvent(). You should definitely pass cefpython.VK_LSHIFT as
modifiers parameter to SendKeyEvent(), so the code is:

    SendKeyEvent(cefpython.KEYTYPE_KEYDOWN, (cefpython.VK_TAB, false, false), cefpython.VK_LSHIFT);

Czarek.

Czarek Tomczak

unread,
Feb 12, 2013, 4:09:22 PM2/12/13
to cefp...@googlegroups.com
There is also cefpython.VK_SHIFT, try both VK_LSHIFT & VK_SHIFT.

Czarek.

cool_...@hotmail.com

unread,
Feb 13, 2013, 3:17:34 AM2/13/13
to cefp...@googlegroups.com
Hi Czarek Tomczak

thanks for the reply. I have tried all of those methods without any luck, i forgot to mention that self.keyinfo returns the tuble like (cefpython.VK_TAB, false, false).

The funny thing is that even if i set the modifier the sendkey acts like a normal tab, tabbing down the page, it's like it doesn't register that the modifier is set and it need to simulate the shift key!

cheers
c_bb

Czarek Tomczak

unread,
Feb 13, 2013, 9:36:53 AM2/13/13
to cefp...@googlegroups.com
In CEF binaries you can find "cefclient.exe" application, in Tests menu there
is an off-screen rendering example, it uses SendKeyEvent() and it works fine,
the c++ code is here:


You haven't answered my question, whether sending shift key works in a textarea.

The funny thing is that even if i set the modifier the sendkey acts like a normal tab, tabbing down the page, it's like it doesn't register that the modifier is set and it need to simulate the shift key!

I'm not sure I understand, are you saying that the "modifiers" parameter doesn't work
for sending shift, but it works when you simulate KEYTYPE_KEYDOWN for shift?

Did you try this?

    SendKeyEvent(cefpython.KEYTYPE_KEYDOWN, (cefpython.VK_SHIFT, false, false), 0);
    SendKeyEvent(cefpython.KEYTYPE_KEYDOWN, (cefpython.VK_TAB, false, false), cefpython.VK_SHIFT);

Czarek.

cool_...@hotmail.com

unread,
Feb 13, 2013, 4:38:44 PM2/13/13
to cefp...@googlegroups.com
Hi Czarek

i tried:


SendKeyEvent(cefpython.KEYTYPE_KEYDOWN, (cefpython.VK_SHIFT, false, false), 0);
SendKeyEvent(cefpython.KEYTYPE_KEYDOWN, (cefpython.VK_TAB, false, false), cefpython.VK_SHIFT);

no luck! all is does is send a normal tab to the browser, so that the diplay page tabs down the page!

regarding your cefclient, off-screen rendering example, that works fine and i can also my code to tab back up the page if i *manually* hold down the shift key and use the sendkey to send the cefpython.VK_TAB, but that is not what i want! i want the up key on the key board to simulate a shift+tab key stroke, so when i press the up key on the keyboard the page displayed will tab upwards! hope it makes sence!

>You haven't answered my question, whether sending shift key works in a textarea.

I tried to send following code to the browser, while focused in textbox:
SendKeyEvent(cefpython.KEYTYPE_KEYDOWN, (cefpython.VK_A, False, False), cefpython.VK_SHIFT)
nothing happened! also tried:
SendKeyEvent(cefpython.KEYTYPE_KEYDOWN, (cefpython.VK_A, False, False), 0)
nothing happened!

> but it works when you simulate KEYTYPE_KEYDOWN for shift?

Don't know, nothing really happens when i send the shift key alone, so i can't see if that works or not! but i guess so!

cheers
c_bb

Czarek Tomczak

unread,
Feb 13, 2013, 5:03:05 PM2/13/13
to cefp...@googlegroups.com
This works fine for sending shift+a to textarea:

    self.browser.SendKeyEvent(cefpython.KEYTYPE_CHAR,
                (cefpython.VK_A, False, False), cefpython.VK_SHIFT)

Regarding shift+tab try google "WM_KEYDOWN shift tab" there
are some solutions, you will probably need to use pywin32 extension
and use some winapi functions.

Czarek.

cool_...@hotmail.com

unread,
Feb 14, 2013, 3:39:30 AM2/14/13
to cefp...@googlegroups.com
hi Czarek

i also tried:

SendKeyEvent(cefpython.KEYTYPE_CHAR, (cefpython.VK_A, False, False), 0)

and that sends a capital A too, even though shift is not send with it!

cheers
c_bb

Czarek Tomczak

unread,
Feb 14, 2013, 11:09:18 AM2/14/13
to cefp...@googlegroups.com
c_bb, 

Windows keyboard input seems complicated.

Read this regarding case-sensitive problems:

WM_CHAR (KEYTYPE_CHAR) is a translation of WM_KEYDOWN (KEYTYPE_KEYDOWN)
messages, but it uses different key codes, you can pass VK_SHIFT only to WM_KEYDOWN,
WM_CHAR already uses different key codes for upper/lower case letters, lower A in
WM_CHAR key code is 0x61 (VK_NUMPAD1), this will print lower A:

SendKeyEvent(cefpython.KEYTYPE_CHAR, (0x61, False, False), 0)

I suggest finding a library that will easy sending keyboard input, as understanding winapi
keyboard input is not trivial. Have a look at "SendKeys":

SendKeysCtypes.py in pywinauto project:

Others similar:

Cheers,
Czarek.

Czarek Tomczak

unread,
Feb 14, 2013, 11:16:27 AM2/14/13
to cefp...@googlegroups.com
I have updated wiki page for the SendKeyEvent() method, with the recommendation

Cheers,
Czarek.
Reply all
Reply to author
Forward
0 new messages