/ld27

To get this branch, use:
bzr branch /bzr/ld27

« back to all changes in this revision

Viewing changes to zoetrope/input/keys.lua

  • Committer: Josh C
  • Date: 2014-07-03 14:41:57 UTC
  • Revision ID: josh@9ix.org-20140703144157-xydxt62xzcdq6bdk
cluke009 zoetrope + my spritebatch changes

Show diffs side-by-side

added added

removed removed

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
 
37
44
        -- private property: _lastFrame
38
45
        -- what keys were pressed last frame
39
46
        
44
51
                the.keys = obj
45
52
                love.keypressed = function (key, unicode) obj:keyPressed(key, unicode) end
46
53
                love.keyreleased = function (key, unicode) obj:keyReleased(key, unicode) end
 
54
                love.textinput = function (text) obj:textInput(text) end
47
55
                if obj.onNew then obj:onNew() end
48
56
                return obj
49
57
        end,
204
212
                return unpack(result)
205
213
        end,
206
214
 
 
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
 
207
229
        -- Converts a character code to a Unicode string
208
230
        -- see http://stackoverflow.com/questions/7780179/what-is-the-way-to-represent-a-unichar-in-lua/7799843
209
231
 
217
239
 
218
240
        -- Connects to the love.keypressed callback
219
241
 
220
 
        keyPressed = function (self, key, unicode)
 
242
        keyPressed = function (self, key, isrepeat)
221
243
                self._thisFrame[key] = true
222
 
                if unicode and unicode >= 0x20 and unicode ~= 127 and unicode < 0x3000 then
223
 
                        self.typed = self.typed .. self:unicodeChar(unicode)
224
 
                end
 
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
225
249
 
226
250
                -- aliases for modifiers
227
251
 
234
258
                end
235
259
        end,
236
260
 
 
261
        -- Connects to the love.textinput callback
 
262
 
 
263
        textInput = function (self, text)
 
264
                self.typed = self.typed .. text
 
265
        end,
 
266
 
237
267
        -- Connects to the love.keyreleased callback
238
268
 
239
269
        keyReleased = function (self, key, unicode)