I have been using the OnKey macro "MacroRecorder" from the samples sub-directory. I have come across a problem that I cannot fathom out. when the recorded Macro contains either {up} or {down} key it generates 2 x {up} or 2 x {down} on playback. Can any one tell me why?
TIA
Here is the Macro Recorder Script.
''XBasic
' dim saved recording_macro (index to macro array)
' and global macro array (place to save macro text)
dim shared recording_macro as n
dim global macro_text[255] as c
' trap F2 key - use to start/end recording macro
if a_user.key.value = "{F2}"
a_user.key.handled = .T.
if a_user.key.event = "down"
' 0 in recording_macro means start recording
if recording_macro = 0
recording_macro = -1
statusbar.set_text("Recording - Hit a control key. e.g. Control X")
statusbar.disable()
else
' else, contains the macro key index OR macro key index not
' defined yet
statusbar.enable()
statusbar.set_text("Done recording macro")
recording_macro = 0
end if
end if
else if recording_macro > 0
' recording macro defined (>0) and not 'end macro' {F2}
' so remember this key, if not {CONTROL} or {SHIFT}
'(these not represented by sys_send_keys, which is used
' to play back the macros).
if a_user.key.event = "down"
if a_user.key.value "{CONTROL}" .and. a_user.key.value "{SHIFT}"
macro_text[recording_macro] = macro_text[recording_macro]+a_user.key.value
end if
end if
else if left(a_user.key.value,2) = "{^" .and. len(a_user.key.value) = 4
' A control key was hit - this is either key to record, or
' if not looking for key to record, macro to playback
index = asc(upper(substr(a_user.key.value,3,1)))
if recording_macro ""
a_user.key.handled = .T.
if a_user.key.event = "down"
' plays back the keys. We recorded
sys_send_keys(macro_text[index])
end if
end if
end if
end if
TIA
Here is the Macro Recorder Script.
''XBasic
' dim saved recording_macro (index to macro array)
' and global macro array (place to save macro text)
dim shared recording_macro as n
dim global macro_text[255] as c
' trap F2 key - use to start/end recording macro
if a_user.key.value = "{F2}"
a_user.key.handled = .T.
if a_user.key.event = "down"
' 0 in recording_macro means start recording
if recording_macro = 0
recording_macro = -1
statusbar.set_text("Recording - Hit a control key. e.g. Control X")
statusbar.disable()
else
' else, contains the macro key index OR macro key index not
' defined yet
statusbar.enable()
statusbar.set_text("Done recording macro")
recording_macro = 0
end if
end if
else if recording_macro > 0
' recording macro defined (>0) and not 'end macro' {F2}
' so remember this key, if not {CONTROL} or {SHIFT}
'(these not represented by sys_send_keys, which is used
' to play back the macros).
if a_user.key.event = "down"
if a_user.key.value "{CONTROL}" .and. a_user.key.value "{SHIFT}"
macro_text[recording_macro] = macro_text[recording_macro]+a_user.key.value
end if
end if
else if left(a_user.key.value,2) = "{^" .and. len(a_user.key.value) = 4
' A control key was hit - this is either key to record, or
' if not looking for key to record, macro to playback
index = asc(upper(substr(a_user.key.value,3,1)))
if recording_macro ""
a_user.key.handled = .T.
if a_user.key.event = "down"
' plays back the keys. We recorded
sys_send_keys(macro_text[index])
end if
end if
end if
end if
Comment