[python] how to: prelinkovanie klavesovych skratiek
greppi
greppi.net na gmail.com
Sobota Březen 22 11:21:13 CET 2008
No nieco som nasiel na
http://programujte.com/index.php?akce=clanek&cl=2007061704-modul-win32com
funguje mi to, ale ked to dam do skriptu ktory som spominal minule
(http://timgolden.me.uk/python/win32_how_do_i/catch_system_wide_hotkeys.html),
tak mi to ignoruje metodu SendKeys, neviete preco ?
ked dam SendKeys samostatne do programu tak to v pohode ide. Myslim ze
problem bude niekde v slucke "while user32.GetMessageA (byref (msg),
None, 0, 0) != 0:"... ale nie som si isty ...
tu je kod:
*import ctypes
from ctypes import wintypes
import win32con
import win32com.client
byref = ctypes.byref
user32 = ctypes.windll.user32
charC = 0x43
charV = 0x56
HOTKEYS = {
1 : (charC, win32con.MOD_WIN), # C + WIN
2 : (charV, win32con.MOD_WIN), # V + WIN
}
def handle_win_c ():
print 'kombinacia win+c ide'
def handle_win_v ():
shell = win32com.client.Dispatch("WScript.Shell")
shell.SendKeys("ABC", 0)
print 'kombinacia win+v ide, ale ignoruje predchadzajuce 2 prikazy'
HOTKEY_ACTIONS = {
1 : handle_win_c,
2 : handle_win_v,
}
*/#
# RegisterHotKey takes:
# Window handle for WM_HOTKEY messages (None = this thread)
# arbitrary id unique within the thread
# modifiers (MOD_SHIFT, MOD_ALT, MOD_CONTROL, MOD_WIN)
# VK code (either ord ('x') or one of win32con.VK_*)
#/*
for id, (vk, modifiers) in HOTKEYS.items ():
print "Registering id", id, "for key", vk
if not user32.RegisterHotKey (None, id, modifiers, vk):
print "Unable to register id", id
print '\n\nStlacte WIN+c, alebo WIN+v pre skusku\n'
*/#
# Home-grown Windows message loop: does
# just enough to handle the WM_HOTKEY
# messages and pass everything else along.
#/*
try:
msg = wintypes.MSG ()
while user32.GetMessageA (byref (msg), None, 0, 0) != 0:
if msg.message == win32con.WM_HOTKEY:
action_to_take = HOTKEY_ACTIONS.get (msg.wParam)
if action_to_take:
action_to_take ()
user32.TranslateMessage (byref (msg))
user32.DispatchMessageA (byref (msg))
finally:
for id in HOTKEYS.keys ():
user32.UnregisterHotKey (None, id)
*
greppi wrote:
> greppi wrote:
>> Caute,
>>
>> potreboval by som spravit program, ktory by mi bezal na pozadi, a
>> keby som stlacil klavesu napr. WIN + V, tak by docielil to aby si WIN
>> XP myslel, ze som stlacil uplne inu kombinaciu skratiek (napr.
>> CTRL+ALT+V).
>>
>> V praxi to znamena, ze napr. pomocou WIN+V, vyvolam akciu (napr.
>> spustim program), ktora sa vyvolava CTRL+ALT+V.
>>
>> /v Pythone som novy, tak prepacte ak sa pytam mozno somarinu, ale ani
>> netusim ako by som toto mohol najst na nete, lebo dost tazko sa to
>> vysvetluje aj v slovencine./
>>
> na internete som nasiel, ako sa daju nastavit globalne skratky
> http://timgolden.me.uk/python/win32_how_do_i/catch_system_wide_hotkeys.html
> , ale este som neprisiel na to, ako spravit, aby sa po stlaceni
> skratky (napr. WIN + V) stlacila "akoze" druha skratka (tu druhu
> skratku stlaci python, tak aby si OS myslel ze som ju stlacil ja
> manualne) ...
>
> cize, aby to bolo zrozumitelnejsie:
>
> chcel by som teraz program, ktory by po spusteni "stlacil" napr
> CTRL+ALT+V, a aby si WIN XP myslel ze som stlacil CTRL+ALT+V ja manulane.
>
Další informace o konferenci Python