Differentiating active browser text fields ("in focus") versus just the browser

I'd like to use the same keyboard shortcuts to perform different actions in a web browser and wonder if this is possible. Specifically:

  • When the browser is at the front but no fields are in focus/ active, I want "command + k" to make the web search box active.
  • However, when I'm in an active field in the address bar or within the browser, I'd like "command + k" to move the cursor to the beginning of the word.

Is such behavior possible? Is KM able to recognize where the cursor context of this sort and then take conditional statements for a given keyboard command?