diff --git a/PythonLib/full/_sendkeys.py b/PythonLib/full/_sendkeys.py new file mode 100644 index 00000000..1c170860 --- /dev/null +++ b/PythonLib/full/_sendkeys.py @@ -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 ) diff --git a/PythonLib/full_dll/_sendkeys.pyd b/PythonLib/full_dll/_sendkeys.pyd deleted file mode 100644 index db3672e7..00000000 Binary files a/PythonLib/full_dll/_sendkeys.pyd and /dev/null differ diff --git a/PythonLib/min/_sendkeys.py b/PythonLib/min/_sendkeys.py new file mode 100644 index 00000000..1c170860 --- /dev/null +++ b/PythonLib/min/_sendkeys.py @@ -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 )