views:

35

answers:

2

Hey, I'm having some trouble here...

How can I delete an entire text from a field with the sendkeys ?

How can I send the ctrl+shift pressed with the left arrow and delete key after?

edit:

for example, I have this part of the code

ctypes.windll.user32.SetCursorPos(910,475)
win32api.mouse_event(win32con.MOUSEEVENTF_LEFTDOWN, 0, 0, 0)
win32api.mouse_event(win32con.MOUSEEVENTF_LEFTUP, 0, 0, 0)
time.sleep(0.1)
shell.SendKeys(inf_firstname)

This part select a field and paste the firstname information (just like a macro), but I want to do something before paste the information that deletes the content of the field, if it has one...

capiche?

+2  A: 

Might want to do Ctrl+A instead? Can you give a short example of the code that isn't working for you?

Depending on the implementation of SendKeys, it might not accept all those at once. It might require multiple SendKeys invocations. You could try doing one at a time, in separate calls to SendKeys.

Edit:

http://msdn.microsoft.com/en-us/library/8c6yea83.aspx

It seems to me you should be able to do this:

shell.SendKeys("^a")
shell.SendKeys("{DELETE}")
Merlyn Morgan-Graham
could be, but how can I do it?
Shady
+2  A: 

I don't know with Sendkeys but I know that you can send keystrokes with ctypes.

Here is how to remove a text by sending CTRL+A and BACK:

ctypes.windll.user32.keybd_event(0x11, 0, 0, 0) #CTRL is down
ctypes.windll.user32.keybd_event(ord("A"), 0, 0, 0) #A is down
ctypes.windll.user32.keybd_event(ord("A"), 0, 0x0002, 0) #A is up
ctypes.windll.user32.keybd_event(0x11, 0, 0x0002, 0) #CTRL is up
ctypes.windll.user32.keybd_event(0x08, 0, 0, 0) #BACK is down
ctypes.windll.user32.keybd_event(0x08, 0, 0x0002, 0) #BACK is up

You need to send the windows virtual key code. See here for the full list.

It may be similar with SendKeys

I hope it helps

luc