/ld27

To get this branch, use:
bzr branch http://9ix.org/bzr/ld27

« back to all changes in this revision

Viewing changes to zoetrope/input/keys.lua

  • Committer: Josh C
  • Date: 2013-08-25 00:32:21 UTC
  • Revision ID: josh@9ix.org-20130825003221-632jbug07yhqabuo
pickĀ upĀ goals

Show diffs side-by-side

added added

removed removed

Lines of Context:
34
34
 
35
35
        _thisFrame = {},
36
36
 
37
 
        -- private property: _alreadyHandled
38
 
        -- was the key already processed by the user code since it was pressed?
39
 
        -- Useful for handling repeated keys, check <pressed> and then you can see
40
 
        -- if the key was repeated.
41
 
 
42
 
        _alreadyHandled = {},
43
 
 
44
37
        -- private property: _lastFrame
45
38
        -- what keys were pressed last frame
46
39
        
51
44
                the.keys = obj
52
45
                love.keypressed = function (key, unicode) obj:keyPressed(key, unicode) end
53
46
                love.keyreleased = function (key, unicode) obj:keyReleased(key, unicode) end
54
 
                love.textinput = function (text) obj:textInput(text) end
55
47
                if obj.onNew then obj:onNew() end
56
48
                return obj
57
49
        end,
212
204
                return unpack(result)
213
205
        end,
214
206
 
215
 
        -- Method: alreadyHandled
216
 
        -- Returns whether this key was already handled since it was pressed.
217
 
        -- Also sets the flag that something was handled, when calling.
218
 
 
219
 
        alreadyHandled = function (self, key)
220
 
                if not self._alreadyHandled[key] then
221
 
                        -- mark preemptively as handled
222
 
                        self._alreadyHandled[key] = true
223
 
                        -- return false, because we need to handle it
224
 
                        return false
225
 
                end
226
 
                return true
227
 
        end,
228
 
 
229
207
        -- Converts a character code to a Unicode string
230
208
        -- see http://stackoverflow.com/questions/7780179/what-is-the-way-to-represent-a-unichar-in-lua/7799843
231
209
 
239
217
 
240
218
        -- Connects to the love.keypressed callback
241
219
 
242
 
        keyPressed = function (self, key, isrepeat)
 
220
        keyPressed = function (self, key, unicode)
243
221
                self._thisFrame[key] = true
244
 
 
245
 
                self._alreadyHandled[key] = false
246
 
                --if unicode and unicode >= 0x20 and unicode ~= 127 and unicode < 0x3000 then
247
 
                --      self.typed = self.typed .. self:unicodeChar(unicode)
248
 
                --end
 
222
                if unicode and unicode >= 0x20 and unicode ~= 127 and unicode < 0x3000 then
 
223
                        self.typed = self.typed .. self:unicodeChar(unicode)
 
224
                end
249
225
 
250
226
                -- aliases for modifiers
251
227
 
258
234
                end
259
235
        end,
260
236
 
261
 
        -- Connects to the love.textinput callback
262
 
 
263
 
        textInput = function (self, text)
264
 
                self.typed = self.typed .. text
265
 
        end,
266
 
 
267
237
        -- Connects to the love.keyreleased callback
268
238
 
269
239
        keyReleased = function (self, key, unicode)