Skip to content

Commit ae36545

Browse files
committed
Fix issue Support for SendKeys module #183
1 parent c71da3e commit ae36545

File tree

3 files changed

+192
-0
lines changed

3 files changed

+192
-0
lines changed

PythonLib/full/_sendkeys.py

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
'''
2+
3+
Sendkeys module moved back to ctypes.
4+
For x64 systems, for example.
5+
6+
(c) 2009 Igor S. Mandrigin, Agnitum Ltd.
7+
8+
'''
9+
10+
from ctypes import windll
11+
12+
# from the internet
13+
KEYEVENTF_KEYUP = 2
14+
VK_NUMLOCK = 144
15+
KEYEVENTF_EXTENDEDKEY = 1
16+
KEYEVENTF_KEYUP = 2
17+
18+
19+
def _key_down( vk ) :
20+
21+
scan = windll.user32.MapVirtualKeyA( vk, 0 )
22+
windll.user32.keybd_event( vk, scan, 0, 0 )
23+
24+
25+
26+
def _key_up( vk ) :
27+
28+
scan = windll.user32.MapVirtualKeyA( vk, 0 )
29+
windll.user32.keybd_event( vk, scan, KEYEVENTF_KEYUP, 0 )
30+
31+
32+
33+
34+
def toggle_numlock( turn_on ) :
35+
'''
36+
toggle_numlock(int) -> int
37+
38+
Turns NUMLOCK on or off and returns whether
39+
it was originally on or off.
40+
'''
41+
42+
is_on = 0
43+
keys = [];
44+
45+
is_on = windll.user32.GetKeyState( VK_NUMLOCK ) & 1
46+
47+
if is_on != turn_on :
48+
windll.user32.keybd_event(VK_NUMLOCK,
49+
69,
50+
KEYEVENTF_EXTENDEDKEY | 0,
51+
0);
52+
windll.user32.keybd_event(VK_NUMLOCK,
53+
69,
54+
KEYEVENTF_EXTENDEDKEY | KEYEVENTF_KEYUP,
55+
0);
56+
57+
58+
59+
return is_on
60+
61+
62+
def char2keycode( char ) :
63+
'''
64+
char2keycode(char) -> int
65+
66+
Converts character to virtual key code
67+
'''
68+
vk = windll.user32.VkKeyScanA( ord( char ) )
69+
return vk
70+
71+
72+
73+
def key_down( key ) :
74+
'''
75+
key_down(int) -> None
76+
77+
Generates a key pressed event. Takes a
78+
virtual key code.
79+
'''
80+
vk = key
81+
# XXX exception if >= 256
82+
_key_down( vk )
83+
84+
85+
86+
def key_up( key ) :
87+
'''
88+
key_up(int) -> None
89+
90+
Generates a key released event. Takes a
91+
virtual key code.
92+
'''
93+
94+
vk = key
95+
# XXX exception if >= 256
96+
_key_up( vk )

PythonLib/full_dll/_sendkeys.pyd

-33.5 KB
Binary file not shown.

PythonLib/min/_sendkeys.py

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
'''
2+
3+
Sendkeys module moved back to ctypes.
4+
For x64 systems, for example.
5+
6+
(c) 2009 Igor S. Mandrigin, Agnitum Ltd.
7+
8+
'''
9+
10+
from ctypes import windll
11+
12+
# from the internet
13+
KEYEVENTF_KEYUP = 2
14+
VK_NUMLOCK = 144
15+
KEYEVENTF_EXTENDEDKEY = 1
16+
KEYEVENTF_KEYUP = 2
17+
18+
19+
def _key_down( vk ) :
20+
21+
scan = windll.user32.MapVirtualKeyA( vk, 0 )
22+
windll.user32.keybd_event( vk, scan, 0, 0 )
23+
24+
25+
26+
def _key_up( vk ) :
27+
28+
scan = windll.user32.MapVirtualKeyA( vk, 0 )
29+
windll.user32.keybd_event( vk, scan, KEYEVENTF_KEYUP, 0 )
30+
31+
32+
33+
34+
def toggle_numlock( turn_on ) :
35+
'''
36+
toggle_numlock(int) -> int
37+
38+
Turns NUMLOCK on or off and returns whether
39+
it was originally on or off.
40+
'''
41+
42+
is_on = 0
43+
keys = [];
44+
45+
is_on = windll.user32.GetKeyState( VK_NUMLOCK ) & 1
46+
47+
if is_on != turn_on :
48+
windll.user32.keybd_event(VK_NUMLOCK,
49+
69,
50+
KEYEVENTF_EXTENDEDKEY | 0,
51+
0);
52+
windll.user32.keybd_event(VK_NUMLOCK,
53+
69,
54+
KEYEVENTF_EXTENDEDKEY | KEYEVENTF_KEYUP,
55+
0);
56+
57+
58+
59+
return is_on
60+
61+
62+
def char2keycode( char ) :
63+
'''
64+
char2keycode(char) -> int
65+
66+
Converts character to virtual key code
67+
'''
68+
vk = windll.user32.VkKeyScanA( ord( char ) )
69+
return vk
70+
71+
72+
73+
def key_down( key ) :
74+
'''
75+
key_down(int) -> None
76+
77+
Generates a key pressed event. Takes a
78+
virtual key code.
79+
'''
80+
vk = key
81+
# XXX exception if >= 256
82+
_key_down( vk )
83+
84+
85+
86+
def key_up( key ) :
87+
'''
88+
key_up(int) -> None
89+
90+
Generates a key released event. Takes a
91+
virtual key code.
92+
'''
93+
94+
vk = key
95+
# XXX exception if >= 256
96+
_key_up( vk )

0 commit comments

Comments
 (0)