10 sec poll - please reply!

M

Michael Herrmann

Hi,

I'm developing a GUI Automation library (http://www.getautoma.com) and am having difficulty picking a name for the function that simulates key strokes.. I currently have it as 'type' but that clashes with the built-in function.. Example uses of 'type':

type(ENTER)

type("Hello World!")

type(CTRL + 'a')

What, in your view, would be the most intuitive alternative name?

Here are my thoughts so far: I could call it 'press' but then our GUI automation tool also allows you to click things and then "press" might be mistaken for "pressing a button". A less ambiguous alternative is "type_keys" butthat is rather long and doesn't read as well, for instance in type_keys(ENTER).

Thank you very much!
 
C

Chris Angelico

Hi,

I'm developing a GUI Automation library (http://www.getautoma.com) and am having difficulty picking a name for the function that simulates key strokes. I currently have it as 'type' but that clashes with the built-in function. Example uses of 'type':

type(ENTER)

type("Hello World!")

type(CTRL + 'a')

What, in your view, would be the most intuitive alternative name?

I've done similar things under names like "send_keys".

ChrisA
 
S

Steven D'Aprano

You know, you would probably get more responses if you picked a
descriptive subject line that didn't look like spam. I only read your
post because I accidentally clicked on it.

I'm developing a GUI Automation library (http://www.getautoma.com) and

By the way, your website is down.

am having difficulty picking a name for the function that simulates key
strokes. I currently have it as 'type' but that clashes with the
built-in function. Example uses of 'type':

type(ENTER)
type("Hello World!")
type(CTRL + 'a')

What, in your view, would be the most intuitive alternative name?


I'd keep the name as "type". It exists in a different namespace to the
builtin, so people have a choice: they can refer to the fully-qualified
name, or not, as they prefer. I don't know the name of your module, since
your website is down, but let's say it's called "automata":

# Option 1
import automata
automata.type("Hello World")


# Option 2
from automata import type
type("Hello World"
import builtins # in Python 2 use __builtin__ instead
builtins.type([])



So the name clash doesn't matter.
 
M

Michael Herrmann

Hi,

thank you for your replies. So far two people said 'send_keys' and one person said 'type'.

Steven, thanks for your reply. Sorry if the message title disturbed you. Mypersonal feelings aren't too strongly against 'type' either, but then I'm afraid it might bother more experienced Python programmers who are used to a very different meaning of 'type'. Do you think that could be a problem?

Thanks again to all who have replied,
Michael
 
M

Michael Herrmann

P.S.: The website is back online; our hosting provider was having technicalproblems...
 
D

Dave Angel

Hi,

I'm developing a GUI Automation library (http://www.getautoma.com) and am having difficulty picking a name for the function that simulates key strokes. I currently have it as 'type' but that clashes with the built-in function. Example uses of 'type':

type(ENTER)

type("Hello World!")

type(CTRL + 'a')

What, in your view, would be the most intuitive alternative name?

Here are my thoughts so far: I could call it 'press' but then our GUI automation tool also allows you to click things and then "press" might be mistaken for "pressing a button". A less ambiguous alternative is "type_keys" but that is rather long and doesn't read as well, for instance in type_keys(ENTER).

Thank you very much!

I also vote for send_keys(), even before I saw Chris' reply.

'type' is too overloaded a word. For example, in Windows, it's the
command to display the contents of a file - it types it to the screen.
 
N

Neil Cerutti

I also vote for send_keys(), even before I saw Chris' reply.

'type' is too overloaded a word. For example, in Windows, it's
the command to display the contents of a file - it types it to
the screen.

type is a nice verb, but since it's also a well-used noun it's
perhaps not quite as good as send.
 
M

Michael Herrmann

Thanks again for your further replies. So far, it's 4 votes for 'send_keys'and 1 vote for 'type'.

Regarding 'send_keys': To me personally it makes sense to send keys _to_ something. However, in our API, send_keys would not be called on an object orwith a parameter indicating the target. It would just be

send_keys(ENTER)
send_keys("Hello World!")
send_keys(CTRL + 'a')

Does that change your preference for 'send_keys'?

Thanks a lot!!!
 
M

MRAB

Thanks again for your further replies. So far, it's 4 votes for 'send_keys' and 1 vote for 'type'.

Regarding 'send_keys': To me personally it makes sense to send keys _to_ something. However, in our API, send_keys would not be called on an object or with a parameter indicating the target. It would just be

send_keys(ENTER)
send_keys("Hello World!")
send_keys(CTRL + 'a')

Does that change your preference for 'send_keys'?
Calling it "send_keys" does have precedent.

There's a module called SendKeys which uses the SendKeys system call in
Windows. Unfortunately, the last version was for Python 2.6.

When I wanted the functionality for Python 3.3 I had to write my own.
 
D

Dave Angel

keyboard_input().

Well, since Python already has input() and raw_input(), it would then be
clear that keyboard_input() would take some kind of data from the
keyboard, not send it.
 
S

Steven D'Aprano

Thanks again for your further replies. So far, it's 4 votes for
'send_keys' and 1 vote for 'type'.

Regarding 'send_keys': To me personally it makes sense to send keys _to_
something. However, in our API, send_keys would not be called on an
object or with a parameter indicating the target. It would just be

send_keys(ENTER)
send_keys("Hello World!")
send_keys(CTRL + 'a')


"send_keys" is wrong, because you aren't sending keys. You're sending
strings, except you aren't actually sending strings either, because
"send" does not make sense without a target. You're automating the typing
of strings, including control characters.

I believe that your initial instinct for the name of this function was
correct. It automates typing, so you should call it "type" or (for those
paranoid about shadowing the built-in, "type_str".
 
E

emile

Hi,

I'm developing a GUI Automation library (http://www.getautoma.com) and am having difficulty picking a name for the function that simulates key strokes. I currently have it as 'type' but that clashes with the built-in function. Example uses of 'type':

type(ENTER)

type("Hello World!")

type(CTRL + 'a')

What, in your view, would be the most intuitive alternative name?

Here are my thoughts so far: I could call it 'press'

I have several tools that distinguish between press and release for
this. You may want to consider having both.

Emile
 
M

mherrmann.at

That's a very good suggestion Emile!! So I might eventually need both 'press' and 'release' (or press_key/release_key). Thanks for this!

To everyone else who has been so kind to reply thus far: What do you think of generate_keystrokes? It's a bit long but describes exactly what the function would be doing.

All of you are a great help and I really appreciate it. Thank you!

Michael
 
M

mherrmann.at

That's a very good suggestion Emile!! So I might eventually need both 'press' and 'release' (or press_key/release_key). Thanks for this!

To everyone else who has been so kind to reply thus far: What do you think of generate_keystrokes? It's a bit long but describes exactly what the function would be doing.

All of you are a great help and I really appreciate it. Thank you!

Michael
 
M

Mark Lawrence

Thanks again for your further replies. So far, it's 4 votes for 'send_keys' and 1 vote for 'type'.

Regarding 'send_keys': To me personally it makes sense to send keys _to_ something. However, in our API, send_keys would not be called on an object or with a parameter indicating the target. It would just be

send_keys(ENTER)
send_keys("Hello World!")
send_keys(CTRL + 'a')

In that case I'd just call it keys, that shouldn't cause too much
confusion :) Though keys_pressed comes to mind as an alternative.
 
Y

yujian4newsgroup

I write a mfc application, then I want to use the python to test this application. just as user click that button. Please tell me how to write the python application?
 
E

emile

I write a mfc application, then I want to use the python to test this application. just as user click that button. Please tell me how to write the python application?

I currently use MacroScheduler (http://www.mjtnet.com/) then write
macros from within python and run them using the commands module to test.

Emile
 
C

Chris Angelico

"send_keys" is wrong, because you aren't sending keys. You're sending
strings, except you aren't actually sending strings either, because
"send" does not make sense without a target. You're automating the typing
of strings, including control characters.

That depends on what the function actually does. If it sends a single
command to blat a string, including control characters, to the target,
then yes, it's sending a string. But if, as my reading of the OP tells
me, the last one is "send press-Ctrl, send press-a, send release-a,
send release-Ctrl", then it's sending keys, and the name should say
so. And it's this method that the key-sender in the Yosemite project
uses (though, for hysterical raisins, its function is called "dokey" -
which I am NOT recommending).

ChrisA
 
P

Prasad, Ramit

Steven said:
"send_keys" is wrong, because you aren't sending keys. You're sending
strings, except you aren't actually sending strings either, because
"send" does not make sense without a target. You're automating the typing
of strings, including control characters.

simulate_keypress
simulate_key(s)_down
send_kb_press
fake_typing
send_char(s)


I believe that your initial instinct for the name of this function was
correct. It automates typing, so you should call it "type" or (for those
paranoid about shadowing thebuilt-in, "type_str".

I can too easily see somebody doing from module import *
OR from module import type.


~Ramit



This email is confidential and subject to important disclaimers and
conditions including on offers for the purchase or sale of
securities, accuracy and completeness of information, viruses,
confidentiality, legal privilege, and legal entity disclaimers,
available at http://www.jpmorgan.com/pages/disclosures/email.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,481
Members
44,900
Latest member
Nell636132

Latest Threads

Top