capturing mouse and keys activity while recording
This commit is contained in:
1 parent
04f304908a
commit
617d499295
3 files changed
+205
-2
No files matched your search
+149
-1
@@ -27,11 +27,12 @@ function newAnimation () {
|
||||
|
||||
let totalConsumption = 0
|
||||
let totalCounter = 0
|
||||
|
||||
let pointerIcon
|
||||
return thisObject
|
||||
|
||||
function finalize () {
|
||||
thisObject.stop()
|
||||
pointerIcon = undefined
|
||||
}
|
||||
|
||||
function initialize () {
|
||||
@@ -137,6 +138,153 @@ function newAnimation () {
|
||||
|
||||
/* Media Recording */
|
||||
if (areWeRecording === true) {
|
||||
const DISTANCE_BETWEEN_ICONS = 60
|
||||
const ICON_SIZES = 50
|
||||
|
||||
let mousePointerIcon = canvas.designSpace.iconCollection.get('mouse-pointer')
|
||||
let wheelIcon = canvas.designSpace.iconCollection.get('mouse-wheel')
|
||||
let draggingIcon = canvas.designSpace.iconCollection.get('support')
|
||||
let keyDownIcon = canvas.designSpace.iconCollection.get('tron')
|
||||
|
||||
let leftClickIcon = canvas.designSpace.iconCollection.get('mouse-left-click')
|
||||
let rightClickIcon = canvas.designSpace.iconCollection.get('mouse-right-click')
|
||||
let wheelClickIcon = canvas.designSpace.iconCollection.get('mouse-wheel-click')
|
||||
|
||||
let imagePosition
|
||||
let buttonPressedIcon
|
||||
|
||||
switch (canvas.mouse.action) {
|
||||
case 'moving': {
|
||||
pointerIcon = mousePointerIcon
|
||||
break
|
||||
}
|
||||
case 'dragging': {
|
||||
pointerIcon = draggingIcon
|
||||
break
|
||||
}
|
||||
case 'wheel': {
|
||||
pointerIcon = wheelIcon
|
||||
break
|
||||
}
|
||||
case 'key down': {
|
||||
pointerIcon = mousePointerIcon
|
||||
break
|
||||
}
|
||||
case 'key up': {
|
||||
pointerIcon = mousePointerIcon
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
imagePosition = {
|
||||
x: canvas.mouse.position.x,
|
||||
y: canvas.mouse.position.y
|
||||
}
|
||||
drawMousePointer(pointerIcon, imagePosition, ICON_SIZES)
|
||||
|
||||
switch (canvas.mouse.event.buttons) {
|
||||
case 0: {
|
||||
buttonPressedIcon = undefined
|
||||
break
|
||||
}
|
||||
case 1: {
|
||||
buttonPressedIcon = leftClickIcon
|
||||
break
|
||||
}
|
||||
case 2: {
|
||||
buttonPressedIcon = rightClickIcon
|
||||
break
|
||||
}
|
||||
case 3: {
|
||||
buttonPressedIcon = undefined
|
||||
break
|
||||
}
|
||||
case 4: {
|
||||
buttonPressedIcon = wheelClickIcon
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
imagePosition = {
|
||||
x: canvas.mouse.position.x + DISTANCE_BETWEEN_ICONS,
|
||||
y: canvas.mouse.position.y
|
||||
}
|
||||
drawMousePointer(buttonPressedIcon, imagePosition, ICON_SIZES)
|
||||
|
||||
if (canvas.mouse.event.shiftKey === true) {
|
||||
let icon = canvas.designSpace.iconCollection.get('mouse-wheel')
|
||||
imagePosition = {
|
||||
x: canvas.mouse.position.x - DISTANCE_BETWEEN_ICONS,
|
||||
y: canvas.mouse.position.y - DISTANCE_BETWEEN_ICONS
|
||||
}
|
||||
drawMousePointer(icon, imagePosition, ICON_SIZES)
|
||||
}
|
||||
|
||||
if (canvas.mouse.event.ctrlKey === true || canvas.mouse.event.metaKey === true) {
|
||||
let icon = canvas.designSpace.iconCollection.get('mouse-wheel')
|
||||
imagePosition = {
|
||||
x: canvas.mouse.position.x - DISTANCE_BETWEEN_ICONS,
|
||||
y: canvas.mouse.position.y + DISTANCE_BETWEEN_ICONS
|
||||
}
|
||||
drawMousePointer(icon, imagePosition, ICON_SIZES)
|
||||
}
|
||||
|
||||
if (canvas.mouse.event.altKey === true) {
|
||||
let icon = canvas.designSpace.iconCollection.get('mouse-wheel')
|
||||
imagePosition = {
|
||||
x: canvas.mouse.position.x - DISTANCE_BETWEEN_ICONS,
|
||||
y: canvas.mouse.position.y - 0
|
||||
}
|
||||
drawMousePointer(icon, imagePosition, ICON_SIZES)
|
||||
}
|
||||
|
||||
if (canvas.mouse.event.code === 'ArrowUp') {
|
||||
let icon = canvas.designSpace.iconCollection.get('mouse-wheel')
|
||||
imagePosition = {
|
||||
x: canvas.mouse.position.x - 0,
|
||||
y: canvas.mouse.position.y + DISTANCE_BETWEEN_ICONS
|
||||
}
|
||||
drawMousePointer(icon, imagePosition, ICON_SIZES)
|
||||
}
|
||||
|
||||
if (canvas.mouse.event.code === 'ArrowDown') {
|
||||
let icon = canvas.designSpace.iconCollection.get('mouse-wheel')
|
||||
imagePosition = {
|
||||
x: canvas.mouse.position.x - 0,
|
||||
y: canvas.mouse.position.y + DISTANCE_BETWEEN_ICONS * 2
|
||||
}
|
||||
drawMousePointer(icon, imagePosition, ICON_SIZES)
|
||||
}
|
||||
|
||||
if (canvas.mouse.event.code === 'ArrowLeft') {
|
||||
let icon = canvas.designSpace.iconCollection.get('mouse-wheel')
|
||||
imagePosition = {
|
||||
x: canvas.mouse.position.x - DISTANCE_BETWEEN_ICONS,
|
||||
y: canvas.mouse.position.y + DISTANCE_BETWEEN_ICONS * 2
|
||||
}
|
||||
drawMousePointer(icon, imagePosition, ICON_SIZES)
|
||||
}
|
||||
|
||||
if (canvas.mouse.event.code === 'ArrowRight') {
|
||||
let icon = canvas.designSpace.iconCollection.get('mouse-wheel')
|
||||
imagePosition = {
|
||||
x: canvas.mouse.position.x + DISTANCE_BETWEEN_ICONS,
|
||||
y: canvas.mouse.position.y + DISTANCE_BETWEEN_ICONS * 2
|
||||
}
|
||||
drawMousePointer(icon, imagePosition, ICON_SIZES)
|
||||
}
|
||||
|
||||
function drawMousePointer (icon, imagePosition, imageSize) {
|
||||
if (icon !== undefined) {
|
||||
if (icon.canDrawIcon === true) {
|
||||
browserCanvasContext.drawImage(
|
||||
icon, imagePosition.x,
|
||||
imagePosition.y,
|
||||
imageSize,
|
||||
imageSize)
|
||||
}
|
||||
}
|
||||
}
|
||||
mediaRecorder.capture(browserCanvas)
|
||||
}
|
||||
|
||||
|
||||
@@ -39,6 +39,7 @@ function newCanvas () {
|
||||
bottomSpace: undefined,
|
||||
designSpace: undefined,
|
||||
animation: undefined,
|
||||
mouse: undefined,
|
||||
initialize: initialize,
|
||||
finalize: finalize
|
||||
}
|
||||
@@ -49,6 +50,13 @@ function newCanvas () {
|
||||
let lastContainerMouseOver
|
||||
let lastShortcutKeyRejection
|
||||
|
||||
thisObject.mouse = {
|
||||
position: {
|
||||
x: 0,
|
||||
y: 0
|
||||
},
|
||||
action: ''
|
||||
}
|
||||
return thisObject
|
||||
|
||||
function finalize () {
|
||||
@@ -73,9 +81,12 @@ function newCanvas () {
|
||||
browserCanvas.removeEventListener('drop', onDragDrop, false)
|
||||
|
||||
browserCanvas.removeEventListener('keydown', onKeyDown, false)
|
||||
browserCanvas.removeEventListener('keyup', onKeyUp, false)
|
||||
|
||||
splashScreen = undefined
|
||||
lastContainerMouseOver = undefined
|
||||
|
||||
hisObject.mouse = undefined
|
||||
} catch (err) {
|
||||
if (ERROR_LOG === true) { logger.write('[ERROR] finalize -> err = ' + err.stack) }
|
||||
}
|
||||
@@ -155,6 +166,7 @@ function newCanvas () {
|
||||
|
||||
/* Keyboard events */
|
||||
window.addEventListener('keydown', onKeyDown, true)
|
||||
window.addEventListener('keyup', onKeyUp, true)
|
||||
|
||||
/* Mouse Events */
|
||||
browserCanvas.addEventListener('mousedown', onMouseDown, false)
|
||||
@@ -228,7 +240,15 @@ function newCanvas () {
|
||||
}
|
||||
}
|
||||
|
||||
function onKeyUp (event) {
|
||||
thisObject.mouse.event = event
|
||||
thisObject.mouse.action = 'key up'
|
||||
}
|
||||
|
||||
function onKeyDown (event) {
|
||||
thisObject.mouse.event = event
|
||||
thisObject.mouse.action = 'key down'
|
||||
|
||||
checkMediaRecording(event)
|
||||
|
||||
let nodeOnFocus = canvas.designSpace.workspace.getNodeThatIsOnFocus()
|
||||
@@ -461,6 +481,20 @@ function newCanvas () {
|
||||
|
||||
function onMouseDown (event) {
|
||||
try {
|
||||
thisObject.mouse.event = event
|
||||
thisObject.mouse.position.x = event.pageX
|
||||
thisObject.mouse.position.y = event.pageY - CURRENT_TOP_MARGIN
|
||||
switch (event.buttons) {
|
||||
case 1: {
|
||||
thisObject.mouse.action = 'clicking with left button'
|
||||
break
|
||||
}
|
||||
case 2: {
|
||||
thisObject.mouse.action = 'clicking with right button'
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
let point = event
|
||||
point.x = event.pageX
|
||||
point.y = event.pageY - CURRENT_TOP_MARGIN
|
||||
@@ -571,6 +605,7 @@ function newCanvas () {
|
||||
ignoreNextClick = false
|
||||
return
|
||||
}
|
||||
|
||||
let point = event
|
||||
point.x = event.pageX
|
||||
point.y = event.pageY - CURRENT_TOP_MARGIN
|
||||
@@ -651,6 +686,11 @@ function newCanvas () {
|
||||
|
||||
function onMouseMove (event) {
|
||||
try {
|
||||
thisObject.mouse.event = event
|
||||
thisObject.mouse.position.x = event.pageX
|
||||
thisObject.mouse.position.y = event.pageY - CURRENT_TOP_MARGIN
|
||||
thisObject.mouse.action = 'moving'
|
||||
|
||||
/* Processing the event */
|
||||
let point = event
|
||||
point.x = event.pageX
|
||||
@@ -787,6 +827,11 @@ function newCanvas () {
|
||||
|
||||
function onMouseWheel (event) {
|
||||
try {
|
||||
thisObject.mouse.event = event
|
||||
thisObject.mouse.position.x = event.pageX
|
||||
thisObject.mouse.position.y = event.pageY - CURRENT_TOP_MARGIN
|
||||
thisObject.mouse.action = 'wheel'
|
||||
|
||||
// cross-browser wheel delta
|
||||
var event = window.event || event // old IE support
|
||||
event.delta = Math.max(-1, Math.min(1, event.wheelDelta || -event.detail))
|
||||
@@ -877,6 +922,11 @@ function newCanvas () {
|
||||
function checkDrag (event) {
|
||||
try {
|
||||
if (containerDragStarted === true || floatingObjectDragStarted === true || viewPortBeingDragged === true) {
|
||||
thisObject.mouse.event = event
|
||||
thisObject.mouse.position.x = event.pageX
|
||||
thisObject.mouse.position.y = event.pageY - CURRENT_TOP_MARGIN
|
||||
thisObject.mouse.action = 'dragging'
|
||||
|
||||
browserCanvas.style.cursor = 'grabbing'
|
||||
thisObject.eventHandler.raiseEvent('Dragging', undefined)
|
||||
|
||||
|
||||
@@ -251,7 +251,12 @@ function newDesignSpace () {
|
||||
'toggle-auto-time-scale-auto-min',
|
||||
'toggle-auto-time-scale-auto-max',
|
||||
'toggle-auto-time-scale-auto-min-max',
|
||||
'toggle-auto-time-scale-manual'
|
||||
'toggle-auto-time-scale-manual',
|
||||
'mouse-pointer',
|
||||
'mouse-left-click',
|
||||
'mouse-right-click',
|
||||
'mouse-wheel',
|
||||
'mouse-wheel-click'
|
||||
]
|
||||
|
||||
for (let i = 0; i < iconsNames.length; i++) {
|
||||
|
||||
Reference in new issue
Block a user