{"action":"created","issue":{"url":"https://api.github.com/repos/cogneco/ooc-kean/issues/660","labels_url":"https://api.github.com/repos/cogneco/ooc-kean/issues/660/labels{/name}","comments_url":"https://api.github.com/repos/cogneco/ooc-kean/issues/660/comments","events_url":"https://api.github.com/repos/cogneco/ooc-kean/issues/660/events","html_url":"https://github.com/cogneco/ooc-kean/issues/660","id":114554846,"number":660,"title":"Keyboard / mouse input","user":{"login":"davidhesselbom","id":4319680,"avatar_url":"https://avatars.githubusercontent.com/u/4319680?v=3","gravatar_id":"","url":"https://api.github.com/users/davidhesselbom","html_url":"https://github.com/davidhesselbom","followers_url":"https://api.github.com/users/davidhesselbom/followers","following_url":"https://api.github.com/users/davidhesselbom/following{/other_user}","gists_url":"https://api.github.com/users/davidhesselbom/gists{/gist_id}","starred_url":"https://api.github.com/users/davidhesselbom/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/davidhesselbom/subscriptions","organizations_url":"https://api.github.com/users/davidhesselbom/orgs","repos_url":"https://api.github.com/users/davidhesselbom/repos","events_url":"https://api.github.com/users/davidhesselbom/events{/privacy}","received_events_url":"https://api.github.com/users/davidhesselbom/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/cogneco/ooc-kean/labels/enhancement","name":"enhancement","color":"84b6eb"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-11-02T09:17:03Z","updated_at":"2015-11-02T09:24:12Z","closed_at":null,"body":"It is sometimes useful to have keyboard and mouse input for various reasons. Most of the work to enable this has already been done, so all that remains is to make it easier to register keys and buttons actions.\r\n\r\nThis works:\r\n```ooc\r\n\tkeyPressEvent := Event1<Key> new(func(key: Key) { })\r\n\tkeyPressEventP := keyPressEvent&\r\n\tkeyReleaseEvent := Event1<Key> new(func(key: Key) { })\r\n\tkeyReleaseEventP := keyReleaseEvent&\r\n\r\n... \r\n\r\n// a loop, somewhere\t\r\n\twhile (XPending(window _native display)) {\r\n\t\tevent: XEventOoc\r\n\t\tXNextEvent(window _native display, event&)\r\n\t\tif (event type == KeyPress) {\r\n\t\t\tkey: ULong\r\n\t\t\tkey = XLookupKeysym((event xkey)&, 0) as ULong\r\n\t\t\tkeyPressEventP@ call(key as Key)\r\n\t\t}\r\n\t\tif (event type == KeyRelease) {\r\n\t\t\tkey: ULong\r\n\t\t\tkey = XLookupKeysym((event xkey)&, 0) as ULong\r\n\t\t\tkeyReleaseEventP@ call(key as Key)\r\n\t\t}\r\n\t}\r\n\r\n\tkeyPressEvent = keyPressEvent add(func(key: Key) {\r\n\t\tif (key == Key Space)\r\n\t\t\t// do something\r\n\t\telse if (key == Key LeftControl)\r\n\t\t\t...\r\n\t})\r\n\tkeyPressEventP = keyPressEvent&\r\n```\r\n\r\n... but obviously, this is messy. I propose an `InputHandler` class that belongs to a `window` that has a dictionary of keyboard keys or mouse buttons coupled with a `func` and and that is used like this:\r\n```ooc\r\nkey := Key Space\r\nwindow registerKeyPressEvent(key, func {\r\n\t// do something\r\n})\r\n```\r\nand the loop described above checks, for each event (key press) in the queue, whether it exists in our dictionary, and if so, calls the function, effectively hiding all the stuff in the first code block inside a class."},"comment":{"url":"https://api.github.com/repos/cogneco/ooc-kean/issues/comments/152967516","html_url":"https://github.com/cogneco/ooc-kean/issues/660#issuecomment-152967516","issue_url":"https://api.github.com/repos/cogneco/ooc-kean/issues/660","id":152967516,"user":{"login":"sebastianbaginski","id":13517893,"avatar_url":"https://avatars.githubusercontent.com/u/13517893?v=3","gravatar_id":"","url":"https://api.github.com/users/sebastianbaginski","html_url":"https://github.com/sebastianbaginski","followers_url":"https://api.github.com/users/sebastianbaginski/followers","following_url":"https://api.github.com/users/sebastianbaginski/following{/other_user}","gists_url":"https://api.github.com/users/sebastianbaginski/gists{/gist_id}","starred_url":"https://api.github.com/users/sebastianbaginski/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sebastianbaginski/subscriptions","organizations_url":"https://api.github.com/users/sebastianbaginski/orgs","repos_url":"https://api.github.com/users/sebastianbaginski/repos","events_url":"https://api.github.com/users/sebastianbaginski/events{/privacy}","received_events_url":"https://api.github.com/users/sebastianbaginski/received_events","type":"User","site_admin":false},"created_at":"2015-11-02T09:24:11Z","updated_at":"2015-11-02T09:24:11Z","body":"Good idea.\r\nMaybe we can abstract it even futher with an `EventLoop` class that will be implemented both on windows and unix to handle the native even loop for the whole application. I was thinking about it since https://github.com/cogneco/ooc-kean/pull/607 , as the X11 window could really use the native event dispatch mechanism."}}