Skip to content

Commit

Permalink
Fix issue Support for SendKeys module #183
Browse files Browse the repository at this point in the history
  • Loading branch information
chcg committed Jan 15, 2021
1 parent c71da3e commit ae36545
Show file tree
Hide file tree
Showing 3 changed files with 192 additions and 0 deletions.
96 changes: 96 additions & 0 deletions PythonLib/full/_sendkeys.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
'''
Sendkeys module moved back to ctypes.
For x64 systems, for example.
(c) 2009 Igor S. Mandrigin, Agnitum Ltd.
'''

from ctypes import windll

# from the internet
KEYEVENTF_KEYUP = 2
VK_NUMLOCK = 144
KEYEVENTF_EXTENDEDKEY = 1
KEYEVENTF_KEYUP = 2


def _key_down( vk ) :

scan = windll.user32.MapVirtualKeyA( vk, 0 )
windll.user32.keybd_event( vk, scan, 0, 0 )



def _key_up( vk ) :

scan = windll.user32.MapVirtualKeyA( vk, 0 )
windll.user32.keybd_event( vk, scan, KEYEVENTF_KEYUP, 0 )




def toggle_numlock( turn_on ) :
'''
toggle_numlock(int) -> int
Turns NUMLOCK on or off and returns whether
it was originally on or off.
'''

is_on = 0
keys = [];

is_on = windll.user32.GetKeyState( VK_NUMLOCK ) & 1

if is_on != turn_on :
windll.user32.keybd_event(VK_NUMLOCK,
69,
KEYEVENTF_EXTENDEDKEY | 0,
0);
windll.user32.keybd_event(VK_NUMLOCK,
69,
KEYEVENTF_EXTENDEDKEY | KEYEVENTF_KEYUP,
0);



return is_on


def char2keycode( char ) :
'''
char2keycode(char) -> int
Converts character to virtual key code
'''
vk = windll.user32.VkKeyScanA( ord( char ) )
return vk



def key_down( key ) :
'''
key_down(int) -> None
Generates a key pressed event. Takes a
virtual key code.
'''
vk = key
# XXX exception if >= 256
_key_down( vk )



def key_up( key ) :
'''
key_up(int) -> None
Generates a key released event. Takes a
virtual key code.
'''

vk = key
# XXX exception if >= 256
_key_up( vk )
Binary file removed PythonLib/full_dll/_sendkeys.pyd
Binary file not shown.
96 changes: 96 additions & 0 deletions PythonLib/min/_sendkeys.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
'''
Sendkeys module moved back to ctypes.
For x64 systems, for example.
(c) 2009 Igor S. Mandrigin, Agnitum Ltd.
'''

from ctypes import windll

# from the internet
KEYEVENTF_KEYUP = 2
VK_NUMLOCK = 144
KEYEVENTF_EXTENDEDKEY = 1
KEYEVENTF_KEYUP = 2


def _key_down( vk ) :

scan = windll.user32.MapVirtualKeyA( vk, 0 )
windll.user32.keybd_event( vk, scan, 0, 0 )



def _key_up( vk ) :

scan = windll.user32.MapVirtualKeyA( vk, 0 )
windll.user32.keybd_event( vk, scan, KEYEVENTF_KEYUP, 0 )




def toggle_numlock( turn_on ) :
'''
toggle_numlock(int) -> int
Turns NUMLOCK on or off and returns whether
it was originally on or off.
'''

is_on = 0
keys = [];

is_on = windll.user32.GetKeyState( VK_NUMLOCK ) & 1

if is_on != turn_on :
windll.user32.keybd_event(VK_NUMLOCK,
69,
KEYEVENTF_EXTENDEDKEY | 0,
0);
windll.user32.keybd_event(VK_NUMLOCK,
69,
KEYEVENTF_EXTENDEDKEY | KEYEVENTF_KEYUP,
0);



return is_on


def char2keycode( char ) :
'''
char2keycode(char) -> int
Converts character to virtual key code
'''
vk = windll.user32.VkKeyScanA( ord( char ) )
return vk



def key_down( key ) :
'''
key_down(int) -> None
Generates a key pressed event. Takes a
virtual key code.
'''
vk = key
# XXX exception if >= 256
_key_down( vk )



def key_up( key ) :
'''
key_up(int) -> None
Generates a key released event. Takes a
virtual key code.
'''

vk = key
# XXX exception if >= 256
_key_up( vk )

0 comments on commit ae36545

Please sign in to comment.