# Detecting keypress

**URL:** <https://discourse.julialang.org/t/detecting-keypress/60612>\
**Category:** New to Julia\
**Tags:** scope, gtk\
**Created:** [May 6, 2021, 1:14am UTC](https://discourse.julialang.org/t/detecting-keypress/60612 "2021-05-06T01:14:24Z")\
**Posts on this page:** 1\
**Showing post:** 4

<div class="post-metadata">

**Author:** ![jzr](https://avatars.discourse-cdn.com/v4/letter/j/eb9ed0/32.png) [@jzr](https://discourse.julialang.org/u/jzr)\
**Post date:** [May 6, 2021, 8:30am UTC](https://discourse.julialang.org/t/detecting-keypress/60612/4 "2021-05-06T08:30:22Z")

</div>

Names already existing in the containing scope are assigned into there. Python uses the `nonlocal` keyword for this behavior but doing it automatically is traditional in Lisp which Julia inherits from.

Detailed thread about this:

> [@Referencing local variable before assignment results in unexpected behavior](https://discourse.julialang.org/t/referencing-local-variable-before-assignment-results-in-unexpected-behavior/58088):
>
> Julia version: 1.6.0 I recently had a bug in my code, after isolating the bug, it came down to a piece of code that looks like this: function outer(n) function inner() n = n + 1 end inner() return n end println(outer(3)) 4 My impression was that outer(3) should return 3, but it actually returns 4. Somehow the code in the inner() block assigns value 4 to the variable n outside of its scope. To me this is very counter-intuitive. Is this a bug or intended beh…

---

_[View the full topic](https://discourse.julialang.org/t/detecting-keypress/60612)._
