Zian,
Thank you for that!
I had found that thread before, but it didnt make sense to me while I was quickly scanning thread results...
However with your specific reference to that thread, I re read the thread a few times, and with some tweaking here and there made it work!
So a big thank you from me to you! And a thanks to the author (USER) in the other thread too!
I copy his answer and script below (plus a txt file of the key codes) for future reference in case someone else finds this thread in their search.
PS for some reason Im having difficulty pasting macro configs (the xml code) which I copy from these forums into my EG, ie the PASTE command is greyed out. For example the code at the bottom, the macros wouldnt paste at all before some fiddling in a text file.
When i compare my forum copied text, to the text of a valid macro which i have copied myself from my EG, there are some formatting diffrences, and some lines like
</Macro>
</EventGhost>
<?xml version="1.0" encoding="UTF-8" ?>
<EventGhost Version="1640">
etc
are either missing or in the wrong tab position.
So i have to paste them in a text file, compare to a "good" copy, reformat the text, then I can paste them.
And sometimes if I use the "select all" button on the text box, and copy, it doesnt work ( the formatting is wrong, some </Macro> lines are in the wrond tab position), however if I manualy select all the lines and copy, its fine.....
Any ideas why?
Copy of the solution from another thread below:
User wrote:Hello!
I have solved the Problem by reading the code of SendKeys.py. It's all in there - sorry to have bothered you.
For everyone who wants to hold a key down, or toggle a key state via eventghost - it's quite simple with a little python-script:
Code: Select all
sendInputStruct = eg.WinApi.Dynamic.INPUT()
sendInputStruct.type = eg.WinApi.Dynamic.INPUT_KEYBOARD
sendInputStructPointer = eg.WinApi.Dynamic.pointer(sendInputStruct)
sendInputStructSize = eg.WinApi.Dynamic.sizeof(sendInputStruct)
keyboardStruct = sendInputStruct.ki
keyboardStruct.dwFlags = 0
# Uncomment this line to release a key:
# keyboardStruct.dwFlags = eg.WinApi.Dynamic.KEYEVENTF_KEYUP
# Get the Key-Code from SendKeys.py
keyboardStruct.wVk = 91
eg.WinApi.Dynamic.SendInput(1, sendInputStructPointer, sendInputStructSize)
Just copy this code into a new Python-Script-Command. dwFlags = 0 presses the Key down and holds it. You can then use another Macro with the same code and uncomment the line below, so the key will be released by that script. The key will also be released by a normal SendKeys-Command from Event-ghost.
My Config now looks like this:
Code: Select all
<Macro Name="Start Application Switch" Expanded="True">
<Event Name="X10.ChannelUp" />
<Action Name="Python Script: Windows-Key down">
EventGhost.PythonScript(u'sendInputStruct = eg.WinApi.Dynamic.INPUT()\nsendInputStruct.type = eg.WinApi.Dynamic.INPUT_KEYBOARD\nsendInputStructPointer = eg.WinApi.Dynamic.pointer(sendInputStruct)\nsendInputStructSize = eg.WinApi.Dynamic.sizeof(sendInputStruct)\nkeyboardStruct = sendInputStruct.ki\n\nkeyboardStruct.dwFlags = 0\n# Uncomment this line to release a key:\n# keyboardStruct.dwFlags = eg.WinApi.Dynamic.KEYEVENTF_KEYUP\n\n# Get the Key-Code from SendKeys.py\nkeyboardStruct.wVk = 91\neg.WinApi.Dynamic.SendInput(1, sendInputStructPointer, sendInputStructSize)\n')
</Action>
<Action>
Window.SendKeys(u'{Tabulator}', False)
</Action>
</Macro>
<Macro Name="Stop Application Switch" Expanded="True">
<Event Name="X10.ChannelDown" />
<Action>
Window.SendKeys(u'{LWin}', False)
</Action>
</Macro>
Quick list of the common key codes to be used with the python script:
KEYEVENTF_KEYUP = 2
VK_SHIFT = 16
VK_CONTROL = 17
VK_MENU = 18
PAUSE = 50/1000.0 # 50 milliseconds
# 'codes' recognized as {CODE( repeat)?}
CODES = {
'BACK': 8,
'BACKSPACE': 8,
'BS': 8,
'BKSP': 8,
'BREAK': 3,
'CAP': 20,
'CAPSLOCK': 20,
'DEL': 46,
'DELETE': 46,
'DOWN': 40,
'END': 35,
'ENTER': 13,
'ESC': 27,
'HELP': 47,
'HOME': 36,
'INS': 45,
'INSERT': 45,
'LEFT': 37,
'LWIN': 91,
'NUMLOCK': 144,
'PGDN': 34,
'PGUP': 33,
'PRTSC': 44,
'RIGHT': 39,
'RMENU': 165,
'RWIN': 92,
'SCROLLLOCK': 145,
'SPACE': 32,
'TAB': 9,
'UP': 38,
'DOWN': 40,
'BACKSPACE': 8,
'F1': 112,
'F2': 113,
'F3': 114,
'F4': 115,
'F5': 116,
'F6': 117,
'F7': 118,
'F8': 119,
'F9': 120,
'F10': 121,
'F11': 122,
'F12': 123,
'F13': 124,
'F14': 125,
'F15': 126,
'F16': 127,
'F17': 128,
'F18': 129,
'F19': 130,
'F20': 131,
'F21': 132,
'F22': 133,
'F23': 134,
'F24': 135,