I’m trying to build an auto-suggestion feature for Google Docs that shows suggestions while typing. The main challenge I’m facing is figuring out how to capture when users type or press keys in the document. I need to monitor text input events so my script can trigger the autocomplete functionality at the right moments. Has anyone found a way to listen for keyboard events or text changes in Google Docs using Google Apps Script? I’ve been searching for solutions but haven’t found a clear approach yet. Any guidance on detecting user input events would be really helpful for this project.
totally get ur frustation! apps script is kinda limited with docs. ur best bet might be creating a web app with the docs api, or checking out add-ons. just a heads up, onEdit only works in sheets, not docs. hope that helps!
Nope, you can’t capture keyboard events or real-time typing in Google Docs with Apps Script. The API only works at the document level - there’s no way to listen for keystrokes or typing events. Apps Script just doesn’t have the client-side JavaScript capabilities you’d need for this. Your best bet is building a separate web app that uses the Google Docs API to check for changes periodically. But that won’t give you the instant response you need for auto-suggestions. You could look into Google Workspace Add-ons for more interactive features, but they’ve got major limitations too when it comes to real-time input detection.
Had this exact same problem last year. Google Docs runs in a sandbox that blocks external scripts from tracking what users type in real-time. Apps Script runs server-side and can’t tap into the browser’s DOM events where typing actually happens. I had to completely change my approach - ditched real-time suggestions and built a trigger system with custom menu items and keyboard shortcuts instead. Users highlight text and hit a key combo to manually pull up suggestions. Not as smooth as I wanted, but it’s the only thing that works with Google’s security setup. You could try building a Chrome extension instead - it’d have the right permissions to interact with page content, though getting users to install it is its own headache.