SavinaRoja / PyUserInput

A module for cross-platform control of the mouse and keyboard in python that is simple to install and use.
GNU General Public License v3.0
1.07k stars 244 forks source link

Typing URLs #83

Closed ghacosta closed 8 years ago

ghacosta commented 8 years ago

Hi there, I need to type an URL but k.type_string(url) doesn't do the trick.

Also I tested to iterate the URL string and invoke alt-codes based on ord() like this: `url = 'http://google.com/'

for ch in url:
    #if isn't a special char
    if ord(ch) > 47 and ord(ch) < 58 or ord(ch) > 64 and ord(ch) < 91 or ord(ch) > 96 and ord(ch) < 123:
        k.tap_key(ch)
    else:
        k.press_key(k.alt_key)
        k.tap_key('4')
        k.tap_key('7')
        k.release_key(k.alt_key)
        #k.press_keys([k.alt_key,'4','7'])`

'if' statement works, but I'm not able to insert any special char. Does any knows a way to input special chars?

Thanks in forward.

SavinaRoja commented 8 years ago

Let me see if I've got this straight. Certain characters in your URL string are not being correctly typed. You try to detect these characters based on ascii ranges and if detected you perform ALT+4,7.

For my clarification, what does ALT+4,7 achieve on your system or is it just a stand-in? What characters are special?

ghacosta commented 8 years ago

You're right, I called special characters those which are neither numbers nor letters.

For example, '/, :, @' and so on, for those characters I'm not being able to type it, so I tried, just for testing, try to input 'ALT + 47' which should type a '/', if you try,

But I was wrong, In linux-based sistem you have to use Ctrl + Shift + U + unicode_hex_code

So, my solution was:

ch_hex = hex(ord(ch))
k.press_keys([k.control_key, k.shift_key, 'u', str(ch_hex)[2], str(ch_hex)[3]])