<titledata-rh="true">Keyboard class | Puppeteer</title><metadata-rh="true"name="viewport"content="width=device-width,initial-scale=1"><metadata-rh="true"name="twitter:card"content="summary_large_image"><metadata-rh="true"property="og:url"content="https://pptr.dev/next/api/puppeteer.keyboard"><metadata-rh="true"property="og:locale"content="en"><metadata-rh="true"name="docsearch:language"content="en"><metadata-rh="true"name="docsearch:counter"content="3"><metadata-rh="true"property="og:title"content="Keyboard class | Puppeteer"><metadata-rh="true"name="description"content="Keyboard provides an api for managing a virtual keyboard. The high level api is Keyboard.type(), which takes raw characters and generates proper keydown, keypress/input, and keyup events on your page."><metadata-rh="true"property="og:description"content="Keyboard provides an api for managing a virtual keyboard. The high level api is Keyboard.type(), which takes raw characters and generates proper keydown, keypress/input, and keyup events on your page."><linkdata-rh="true"rel="icon"href="/img/favicon.ico"><linkdata-rh="true"rel="canonical"href="https://pptr.dev/next/api/puppeteer.keyboard"><linkdata-rh="true"rel="alternate"href="https://pptr.dev/next/api/puppeteer.keyboard"hreflang="en"><linkdata-rh="true"rel="alternate"href="https://pptr.dev/next/api/puppeteer.keyboard"hreflang="x-default"><linkdata-rh="true"rel="preconnect"href="https://DVKY664LG7-dsn.algolia.net"crossorigin="anonymous"><linkrel="search"type="application/opensearchdescription+xml"title="Puppeteer"href="/opensearch.xml">
<p>Keyboard provides an api for managing a virtual keyboard. The high level api is <ahref="/next/api/puppeteer.keyboard.type">Keyboard.type()</a>, which takes raw characters and generates proper keydown, keypress/input, and keyup events on your page.</p>
<h4class="anchor anchorWithStickyNavbar_FNw8"id="signature">Signature:<ahref="#signature"class="hash-link"aria-label="Direct link to Signature:"title="Direct link to Signature:"></a></h4>
<h2class="anchor anchorWithStickyNavbar_FNw8"id="remarks">Remarks<ahref="#remarks"class="hash-link"aria-label="Direct link to Remarks"title="Direct link to Remarks"></a></h2>
<p>For finer control, you can use <ahref="/next/api/puppeteer.keyboard.down">Keyboard.down()</a>, <ahref="/next/api/puppeteer.keyboard.up">Keyboard.up()</a>, and <ahref="/next/api/puppeteer.keyboard.sendcharacter">Keyboard.sendCharacter()</a> to manually fire events as if they were generated from a real keyboard.</p>
<p>On macOS, keyboard shortcuts like <code>⌘ A</code> -> Select All do not work. See <ahref="https://github.com/puppeteer/puppeteer/issues/1313"target="_blank"rel="noopener noreferrer">#1313</a>.</p>
<p>The constructor for this class is marked as internal. Third-party code should not call the constructor directly or create subclasses that extend the <code>Keyboard</code> class.</p>
<h2class="anchor anchorWithStickyNavbar_FNw8"id="example-1">Example 1<ahref="#example-1"class="hash-link"aria-label="Direct link to Example 1"title="Direct link to Example 1"></a></h2>
<h2class="anchor anchorWithStickyNavbar_FNw8"id="example-2">Example 2<ahref="#example-2"class="hash-link"aria-label="Direct link to Example 2"title="Direct link to Example 2"></a></h2>
<h2class="anchor anchorWithStickyNavbar_FNw8"id="methods">Methods<ahref="#methods"class="hash-link"aria-label="Direct link to Methods"title="Direct link to Methods"></a></h2>
<table><thead><tr><th><p>Method</p></th><th><p>Modifiers</p></th><th><p>Description</p></th></tr></thead><tbody><tr><td><spanid="down"><ahref="/next/api/puppeteer.keyboard.down">down(key, options)</a></span></td><td></td><td><p>Dispatches a <code>keydown</code> event.</p><p><strong>Remarks:</strong></p><p>If <code>key</code> is a single character and no modifier keys besides <code>Shift</code> are being held down, a <code>keypress</code>/<code>input</code> event will also generated. The <code>text</code> option can be specified to force an input event to be generated. If <code>key</code> is a modifier key, <code>Shift</code>, <code>Meta</code>, <code>Control</code>, or <code>Alt</code>, subsequent key presses will be sent with that modifier active. To release the modifier key, use <ahref="/next/api/puppeteer.keyboard.up">Keyboard.up()</a>.</p><p>After the key is pressed once, subsequent calls to <ahref="/next/api/puppeteer.keyboard.down">Keyboard.down()</a> will have <ahref="https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/repeat"target="_blank"rel="noopener noreferrer">repeat</a> set to true. To release the key, use <ahref="/next/api/puppeteer.keyboard.up">Keyboard.up()</a>.</p><p>Modifier keys DO influence <ahref="/next/api/puppeteer.keyboard.down">Keyboard.down()</a>. Holding down <code>Shift</code> will type the text in upper case.</p></td></tr><tr><td><spanid="press"><ahref="/next/api/puppeteer.keyboard.press">press(key, options)</a></span></td><td></td><td><p>Shortcut for <ahref="/next/api/puppeteer.keyboard.down">Keyboard.down()</a> and <ahref="/next/api/puppeteer.keyboard.up">Keyboard.up()</a>.</p><p><strong>Remarks:</strong></p><p>If <code>key</code> is a single character and no modifier keys besides <code>Shift</code> are being held down, a <code>keypress</code>/<code>input</code> event will also generated. The <code>text</code> option can be specified to force an input event to be generated.</p><p>Modifier keys DO effect <ahref="/next/api/puppeteer.keyboard.press">Keyboard.press()</a>. Holding down <code>Shift</code> will type the text in upper case.</p></td></tr><tr><td><spanid="sendcharacter"><ahref="/next/api/puppeteer.keyboard.sendcharacter">sendCharacter(char)</a></span></td><td></td><td><p>Dispatches a <code>keypress</code> and <code>input</code> event. This does not send a <code>keydown</code> or <code>keyup</code> event.</p><p><strong>Remarks:</strong></p><p>Modifier keys DO NOT effect <ahref="/next/api/puppeteer.keyboard.sendcharacter">Keyboard.sendCharacter</a>. Holding down <code>Shift</code> will not type the text in upper case.</p></td></tr><tr><td><spanid="type"><ahref="/next/api/puppeteer.keyboard.type">type(text, options)</a></span></td><td></td><td><p>Sends a <code>keydown</code>, <code>keypress</code>/<code>input</code>, and <code>keyup</code> event for each character in the text.</p><p><strong>Remarks:</strong></p><p>To press a special key, like <code>Control</code> or <code>ArrowDown</code>, use <ahref="/next/api/puppeteer.keyboard.press">Keyboard.press()</a>.</p><p>Modifier keys DO NOT effect <code>keyboard.type</code>. Holding down <code>Shift</code> will not type the text in upper case.</p></td></tr><tr><td><spanid="up"><ahref="/next/api/puppeteer.keyboard.up">up(key)</a></span></td><td></td><td><p>Dispatches a <code>keyup</code> event.</p></td></tr></tbody></table></div></article><navclass="pagination-nav docusaurus-mt-lg"aria-label="Docs pages"><aclass="pagination-nav__link pagination-nav__link--prev"href="/next/api/puppeteer.accessibility.snapshot"><divclass="pagination-nav__sublabel">Previous</div><divclass="pagination-nav__label">Accessibility.snapshot</div></a><aclass="pagination-nav__link pagination-nav__link--next"href="/next/api/puppeteer.keyboard.down"><divclass="pagination-nav__sublabel">Next</div><divclass="pagination-nav__label">Keyboard.down</div></a></nav></div></div><divclass="col col--3"><divclass="tableOfContents_IS5x thin-scrollbar theme-doc-toc-desktop"><ulclass="table-of-contents table-of-contents__left-border"><li><a