# Moving annotations with arrow keys - Line and text box

**URL:** <https://pdfjs.community/t/moving-annotations-with-arrow-keys-line-and-text-box/2243>\
**Category:** Technical Support\
**Created:** [December 19, 2022, 8:50pm UTC](https://pdfjs.community/t/moving-annotations-with-arrow-keys-line-and-text-box/2243 "2022-12-19T20:50:02Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![shiran305](https://avatars.discourse-cdn.com/v4/letter/s/df705f/32.png) [@shiran305](https://pdfjs.community/u/shiran305)\
**Post date:** [December 19, 2022, 8:50pm UTC](https://pdfjs.community/t/moving-annotations-with-arrow-keys-line-and-text-box/2243/1 "2022-12-19T20:50:02Z")

</div>

**Which product are you using?**  
PDF.js Express Plus

**PDF.js Express Version**  
6.3.4

**Detailed description of issue**  
We are following the method to bind the arrow keys in this other thread [Enable annotations to be moved using arrow keys](https://pdfjs.community/t/enable-annotations-to-be-moved-using-arrow-keys/602). However when we draw a line and then try to move it with the arrow keys it does not work. When we put a free form text box, it only moves the box but not the content. Is there a different binding for the other annotations?

Thanks

---

<div class="post-metadata">

**Author:** ![kkim](https://avatars.discourse-cdn.com/v4/letter/k/3ab097/32.png) [@kkim](https://pdfjs.community/u/kkim)\
**Post date:** [December 19, 2022, 11:02pm UTC](https://pdfjs.community/t/moving-annotations-with-arrow-keys-line-and-text-box/2243/2 "2022-12-19T23:02:50Z")

</div>

Hi there,

Thank you for contacting pdf.js express forums,

I am able to move the line annotation using the code provided from the other post:  
Minor change of instance.iframeWindow.window to instance.UI

```javascript
  const { docViewer, annotManager, Annotations } = instance;

  const adjustSelectedAnnot = (x, y, event) => {

    const selectedAnnots = annotManager.getSelectedAnnotations();

    if (!selectedAnnots || selectedAnnots.length === 0) {
      return;
    }

    event.preventDefault()

    selectedAnnots.forEach(annot => {
      annot.X += x;
      annot.Y += y;
      annotManager.redrawAnnotation(annot);
    })

  }

  instance.iframeWindow.window.addEventListener('keydown', event => {
    switch (event.key) {
      case 'ArrowRight':
        {
          adjustSelectedAnnot(1, 0, event)
          break;
        }
      case 'ArrowLeft':
        {
          adjustSelectedAnnot(-1, 0, event)
          break;
        }
      case 'ArrowUp':
        {
          adjustSelectedAnnot(0, -1, event)
          break
        }
      case 'ArrowDown':
        {
          adjustSelectedAnnot(0, 1, event)
          break;
        }
    }
  })

```

This works on our demo site [PDF.js Viewer Demo | PDF.js Express](https://pdfjs.express/demo) (note this is on 8.7). You just need to make sure the line annotation is selected when you run the code.

Best regards,  
Kevin Kim
