ObjectSendKeys Ideas

Technical support and scripting issues

Moderators: Dorian (MJT support), JRL

Post Reply
User avatar
Phil Pendlebury
Automation Wizard
Posts: 538
Joined: Tue Jan 16, 2007 9:00 am
Contact:

ObjectSendKeys Ideas

Post by Phil Pendlebury » Sat Jul 02, 2022 7:57 am

I have just discovered the ObjectSendKeys command, it is great! One issue I always had was setting focus to various things in order to send key to them.

However I have had to do this kind of thing in order to get it to work.

Example from ini file

Code: Select all

///////////////////////////////////////////////////////////////////////////////
key1txt=Mix 1
key1mod=CTRL+ALT
key1key=114
key1col=Green
///////////////////////////////////////////////////////////////////////////////

Code: Select all

SRT>PRESSKEYS
// mainkey is read from the key1txt of the  ini file
// modkey is read from key1mod of ini file
Let>mainkey=VK%mainkey%
RegEx>%patternc%,%modkey%,0,ctrlarr,ctrlmatches,0,,
RegEx>%patterna%,%modkey%,0,altarr,altmatches,0,,
RegEx>%patterns%,%modkey%,0,shiftarr,shiftmatches,0,,
IF>%ctrlmatches%>0
  Press CTRL
ENDIF
IF>%altmatches%>0
  Press ALT
ENDIF
IF>%shiftmatches%>0
  Press SHIFT
ENDIF
Wait>%waits% // this will be 0.03 at the moment
ObjectSendKeys>%hWndParent%,%mainkey%
//
IF>%ctrlmatches%>0
  Release CTRL
ENDIF
IF>%altmatches%>0
  Release ALT
ENDIF
IF>%shiftmatches%>0
  Release SHIFT
ENDIF
END>PRESSKEYS
Odd things:
If I include the modifier keys in the "ObjectSendKeys" command, it fails. So I have to send them separately, as seen above. This seems to work Ok but sometimes still fails.
Also I am having to make sure %mainkey% is a vk "VK114" for example.
I wish there was a way to allow the user to enter the actual key in my ini file rather than having to ask them to lookup the v key number.
I don't really want to make a big conversion table in the code.

I was just wondering if anyone has found any interesting ways to deal with this scenario?
Phil Pendlebury - Linktree

User avatar
Grovkillen
Automation Wizard
Posts: 1009
Joined: Fri Aug 10, 2012 2:38 pm
Location: Bräcke, Sweden
Contact:

Re: ObjectSendKeys Ideas

Post by Grovkillen » Sat Jul 02, 2022 8:39 pm

I got this from a very good friend here in the forum.

Code: Select all

LabelToVar>VK_Codes,vVKCodes
IncludeFromVar>vVKCodes
/*
VK_Codes:
Let>VK_LBUTTON=1
Let>VK_RBUTTON=2
Let>VK_CANCEL=3
Let>VK_MBUTTON=4
Let>VK_XBUTTON1=5
Let>VK_XBUTTON2=6
Let>VK_BACK=8
Let>VK_TAB=9
Let>VK_CLEAR=12
Let>VK_RETURN=13
Let>VK_SHIFT=16
Let>VK_CONTROL=17
Let>VK_MENU=18
Let>VK_PAUSE=19
Let>VK_CAPITAL=20
Let>VK_KANA=21
Let>VK_HANGUEL=21
Let>VK_HANGUL=21
Let>VK_JUNJA=23
Let>VK_FINAL=24
Let>VK_HANJA=25
Let>VK_KANJI=25
Let>VK_ESCAPE=27
Let>VK_CONVERT=28
Let>VK_NONCONVERT=29
Let>VK_ACCEPT=30
Let>VK_MODECHANGE=31
Let>VK_SPACE=32
Let>VK_PRIOR=33
Let>VK_NEXT=34
Let>VK_END=35
Let>VK_HOME=36
Let>VK_LEFT=37
Let>VK_UP=38
Let>VK_RIGHT=39
Let>VK_DOWN=40
Let>VK_SELECT=41
Let>VK_PRINT=42
Let>VK_EXECUTE=43
Let>VK_SNAPSHOT=44
Let>VK_INSERT=45
Let>VK_DELETE=46
Let>VK_HELP=47
Let>VK_0=48
Let>VK_1=49
Let>VK_2=50
Let>VK_3=51
Let>VK_4=52
Let>VK_5=53
Let>VK_6=54
Let>VK_7=55
Let>VK_8=56
Let>VK_9=57
Let>VK_A=65
Let>VK_B=66
Let>VK_C=67
Let>VK_D=68
Let>VK_E=69
Let>VK_F=70
Let>VK_G=71
Let>VK_H=72
Let>VK_I=73
Let>VK_J=74
Let>VK_K=75
Let>VK_L=76
Let>VK_M=77
Let>VK_N=78
Let>VK_O=79
Let>VK_P=80
Let>VK_Q=81
Let>VK_R=82
Let>VK_S=83
Let>VK_T=84
Let>VK_U=85
Let>VK_V=86
Let>VK_W=87
Let>VK_X=88
Let>VK_Y=89
Let>VK_Z=90
Let>VK_LWIN=91
Let>VK_RWIN=92
Let>VK_APPS=93
Let>VK_SLEEP=95
Let>VK_NUMPAD0=96
Let>VK_NUMPAD1=97
Let>VK_NUMPAD2=98
Let>VK_NUMPAD3=99
Let>VK_NUMPAD4=100
Let>VK_NUMPAD5=101
Let>VK_NUMPAD6=102
Let>VK_NUMPAD7=103
Let>VK_NUMPAD8=104
Let>VK_NUMPAD9=105
Let>VK_MULTIPLY=106
Let>VK_ADD=107
Let>VK_SEPARATOR=108
Let>VK_SUBTRACT=109
Let>VK_DECIMAL=110
Let>VK_DIVIDE=111
Let>VK_F1=112
Let>VK_F2=113
Let>VK_F3=114
Let>VK_F4=115
Let>VK_F5=116
Let>VK_F6=117
Let>VK_F7=118
Let>VK_F8=119
Let>VK_F9=120
Let>VK_F10=121
Let>VK_F11=122
Let>VK_F12=123
Let>VK_F13=124
Let>VK_F14=125
Let>VK_F15=126
Let>VK_F16=127
Let>VK_F17=128
Let>VK_F18=129
Let>VK_F19=130
Let>VK_F20=131
Let>VK_F21=132
Let>VK_F22=133
Let>VK_F23=134
Let>VK_F24=135
Let>VK_NUMLOCK=144
Let>VK_SCROLL=145
Let>VK_LSHIFT=160
Let>VK_RSHIFT=161
Let>VK_LCONTROL=162
Let>VK_RCONTROL=163
Let>VK_LMENU=164
Let>VK_RMENU=165
Let>VK_BROWSER_BACK=166
Let>VK_BROWSER_FORWARD=167
Let>VK_BROWSER_REFRESH=168
Let>VK_BROWSER_STOP=169
Let>VK_BROWSER_SEARCH=170
Let>VK_BROWSER_FAVORITES=171
Let>VK_BROWSER_HOME=172
Let>VK_VOLUME_MUTE=173
Let>VK_VOLUME_DOWN=174
Let>VK_VOLUME_UP=175
Let>VK_MEDIA_NEXT_TRACK=176
Let>VK_MEDIA_PREV_TRACK=177
Let>VK_MEDIA_STOP=178
Let>VK_MEDIA_PLAY_PAUSE=179
Let>VK_LAUNCH_MAIL=180
Let>VK_LAUNCH_MEDIA_SELECT=181
Let>VK_LAUNCH_APP1=182
Let>VK_LAUNCH_APP2=183
Let>VK_OEM_1=186
Let>VK_OEM_PLUS=187
Let>VK_OEM_COMMA=188
Let>VK_OEM_MINUS=189
Let>VK_OEM_PERIOD=190
Let>VK_OEM_2=191
Let>VK_OEM_3=192
Let>VK_OEM_4=219
Let>VK_OEM_5=220
Let>VK_OEM_6=221
Let>VK_OEM_7=222
Let>VK_OEM_8=223
Let>VK_OEM_102=226
Let>VK_PROCESSKEY=229
Let>VK_PACKET=231
Let>VK_ATTN=246
Let>VK_CRSEL=247
Let>VK_EXSEL=248
Let>VK_EREOF=249
Let>VK_PLAY=250
Let>VK_ZOOM=251
Let>VK_NONAME=252
Let>VK_PA1=253
Let>VK_OEM_CLEAR=254
*/ 
Let>ME=%Script%

Running: 15.0.24
version history

User avatar
Grovkillen
Automation Wizard
Posts: 1009
Joined: Fri Aug 10, 2012 2:38 pm
Location: Bräcke, Sweden
Contact:

Re: ObjectSendKeys Ideas

Post by Grovkillen » Sat Jul 02, 2022 8:41 pm

And here you have my suggestion of how to improve the VK implementation.

viewtopic.php?f=8&t=10888
Let>ME=%Script%

Running: 15.0.24
version history

User avatar
Phil Pendlebury
Automation Wizard
Posts: 538
Joined: Tue Jan 16, 2007 9:00 am
Contact:

Re: ObjectSendKeys Ideas

Post by Phil Pendlebury » Sun Jul 03, 2022 8:37 am

Hi thanks,

Yes I already have a list compiled but thanks for that anyway, As mentioned originally, I really don't want to use that method, as it has to be called too often. Your suggestion for improvement would be great though.

:D

Really this question was more about the ObjectSendKeys and why it seems to fail sometimes when using modifier keys (CTRL/ALT etc.).
Phil Pendlebury - Linktree

Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts