• Anmelden

1

Montag, 13. Oktober 2008, 21:03

Button-Input.repeat für Mausscript

Hallo,

Ich habe hier folgendes Mausscript:
Spoiler

Quellcode

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
#==============================================================================
#
# Mouse Script 1.0                                  	created by: cybersam
#                                                   	edited by: MagicMagor
#
#==============================================================================
#
# (got rid of cybersams explanation here, because it isn't true for this module)
#                                                   	MagicMagor
#==============================================================================
 
#==============================================================================
# I have edited cybersams script, to fit my needs and my personal style of
# coding. I have also extended the script and got rid of several bugs. 
# If you use this, give credit to cybersam and me.
#------------------------------------------------------------------------------
# MagicMagor
#==============================================================================
 
module Mouse
 
  MOUSE_LEFT	= 0x01    	# left mouse button
  MOUSE_RIGHT   = 0x02    	# right mouse button
 
  attr_reader :MOUSE_LEFT, :MOUSE_RIGHT
 
  # Flags
 
  INIT_CURSOR = 0x01
  INIT_SAVE = 0x02
  INIT_TYPE = 0x03
  CURSOR_PIC = 0x01
  CURSOR_ROOT = 0x02
  CURSOR_BITMAP = 0x03
 
  attr_reader :INIT_CURSOR, :INIT_SAVE, :INIT_TYPE,
          	:CURSOR_PIC, :CURSOR_ROOT, :CURSOR_BITMAP
 
 
  @getCursorPos = Win32API.new('user32', 'GetCursorPos', 'p', 'i')
  @getWindowRect = Win32API.new('user32', 'GetWindowRect', ['p', 'p'], 'i')
  @scr2cli = Win32API.new('user32', 'ScreenToClient', %w(l p), 'i')
  @client_rect = Win32API.new('user32', 'GetClientRect', %w(l p), 'i')
  @readini = Win32API.new('kernel32', 'GetPrivateProfileStringA', %w(p p p p l p), 'l')
  @findwindow = Win32API.new('user32', 'FindWindow', %w(p p), 'l')
  @getKeyState = Win32API.new("user32","GetAsyncKeyState",['i'],'i')
 
  #---------------------------------------------------------------------------
  # Initialize the mouse-system, with given arguments. Is automaticly called
  # if needed.
  #---------------------------------------------------------------------------
  def Mouse.initSystem(*args)
	@init = true
	@handle = self.getHandle()
	@cursor = Sprite.new()
	if args.length >= 1
  	flags = args[0]
  	@showCursor  = (flags & INIT_CURSOR)
  	@saveToGame = (flags & INIT_SAVE)
  	withType = (flags & INIT_TYPE)
  	if (@showCursor != 0)
    	@showCursor = true
  	else
    	@showCursor = false
  	end
  	if (@saveToGame != 0)
    	@saveToGame = true
  	else
    	@saveToGame = false
  	end
  	@cursor.visible = @showCursor
  	@originX = 0
  	@originY = 0
  	if (@saveToGame)
    	@gameX = args[-2]
    	@gameY = args[-1]
  	end
  	if (@showCursor)
    	if (withType)
      	self.setCursor(args[1], args[2])
    	else
      	self.setCursor(args[1])
    	end
  	end
	end
	return nil
  end
 
  #---------------------------------------------------------------------------
  # Checks if key was pressed.
  #---------------------------------------------------------------------------  
  def Mouse.pressed?(key)
   return ((@getKeyState.call(key) & 0x01) == 1)
  end
  def Mouse.click_area?(startx,endx,starty,endy)
	screenx = $game_variables[1]
	screeny = $game_variables[2]
	if screenx > startx and screenx < endx and screeny > starty and screeny < endy and Mouse.pressed?(Mouse::MOUSE_LEFT)
  	return true
	end
  end
  #---------------------------------------------------------------------------
  # Returns true if saving mouse positions to game-variables is enabled
  #---------------------------------------------------------------------------  
  def Mouse.saveToGame?()
	if !(@init)
  	self.initSystem(nil)
	end
	return @saveToGame
  end
 
  #---------------------------------------------------------------------------
  # Enables saving the mouse positions to game-variables
  #---------------------------------------------------------------------------  
  def Mouse.enableSaveToGame(game_x = nil, game_y = nil )
	if !(@init)
  	self.initSystem(nil)
	end
	@saveToGame = true
	if (game_x != nil)
  	@gameX = game_x
	end
	if (game_y != nil)
  	@gameY = game_y
	end
	return nil
  end
 
  #---------------------------------------------------------------------------
  # Disables saving the mouse positions to game-variables
  #---------------------------------------------------------------------------  
  def Mouse.disableSaveToGame()
	if !(@init)
  	self.initSystem(nil)
	end
	@saveToGame = false
	return nil
  end
 
  #---------------------------------------------------------------------------
  # Sets the variable-ID in which the X position is saved
  #---------------------------------------------------------------------------  
  def Mouse.setGameX(game_x)
	if !(@init)
  	self.initSystem(nil)
	end
	@gameX = game_x
	return nil
  end
 
  #---------------------------------------------------------------------------
  # Sets the variable-ID in which the Y position is saved
  #---------------------------------------------------------------------------  
  def Mouse.setGameY(game_y)
   if !(@init)
  	self.initSystem(nil)
	end
   @gameY = game_y
   return nil
  end
 
  #---------------------------------------------------------------------------
  # Returns the variable-ID in which the X position is saved
  #---------------------------------------------------------------------------  
  def Mouse.gameX
	return @gameX
  end
 
  #---------------------------------------------------------------------------
  # Returns the variable-ID in which the Y position is saved
  #---------------------------------------------------------------------------  
  def Mouse.gameY
	return @gameY
  end
 
  #---------------------------------------------------------------------------
  # Returns X-Value of mouse positions
  #---------------------------------------------------------------------------	
  def Mouse.x()
	if !(@init)
  	self.initSystem(nil)
	end
	x, y = Mouse.mousePos()
	return x
  end
 
  #---------------------------------------------------------------------------
  # Returns Y-Value of mouse positions
  #---------------------------------------------------------------------------	
  def Mouse.y()
	if !(@init)
  	self.initSystem(nil)
	end
	x, y = Mouse.mousePos()
	return y
  end
 
  #---------------------------------------------------------------------------
  # Returns TRUE when the mouse-cursor is shown.
  #---------------------------------------------------------------------------	
  def Mouse.shown?()
	if !(@init)
  	self.initSystem(nil)
	end
	return @showCursor
  end
 
  #---------------------------------------------------------------------------
  # Enables showing of the mouse-cursor.
  #---------------------------------------------------------------------------	
  def Mouse.enableShow()
	if !(@init)
  	self.initSystem(nil)
	end
	@showCursor = true
	@cursor.visible = true
	return nil
  end
 
  #---------------------------------------------------------------------------
  # Disable showing of the mouse-cursor.
  #---------------------------------------------------------------------------	
  def Mouse.disableShow()
	if !(@init)
  	self.initSystem(nil)
	end
	@showCursor = false
	@cursor.visible = false
	return nil
  end
 
  #---------------------------------------------------------------------------
  # Sets a new bitmap for the cursor.
  #---------------------------------------------------------------------------	
  def Mouse.setCursor(filename, type = CURSOR_PIC, originX = 0, originY = 0)
	if !(@init)
  	self.initSystem(nil)
	end
	@originX = originX
	@originY = originY
	case type
	when CURSOR_PIC
  	@cursor.bitmap = RPG::Cache.picture(filename)
  	@cursor.z = 999	
  	return nil
	when CURSOR_ROOT
  	@cursor.bitmap = Bitmap.new(filename)
  	@cursor.z = 999
  	return nil
	when CURSOR_BITMAP
  	@cursor.bitmap = filename
  	@cursor.z = 999
  	return nil
	end
  end
 
  #---------------------------------------------------------------------------
  # Sets the x-coordinate of the cursor-picture origin.
  #---------------------------------------------------------------------------	
  def Mouse.setOriginX(originX)
	if !(@init)
  	self.initSystem(nil)
	end
	@originX = originX
	return nil
  end
 
  #---------------------------------------------------------------------------
  # Sets the y-coordinate of the cursor-picture origin.
  #---------------------------------------------------------------------------	
  def Mouse.setOriginY(originY)
	if !(@init)
  	self.initSystem(nil)
	end
	@originY = originY
	return nil
  end
 
  #---------------------------------------------------------------------------
  # Updates the position of the mouse-cursor on screen.
  #---------------------------------------------------------------------------	
  def Mouse.update()
	if !(@init)
  	self.initSystem(nil)
	end
	if (@showCursor)
  	if Mouse.x() != nil
    	@cursor.x = Mouse.x() - @originX
  	end
  	if Mouse.y() != nil
    	@cursor.y = Mouse.y() - @originY
  	end
	end
	if ((@saveToGame) && (@gameX != nil) && (@gameY != nil))
  	$game_variables[@gameX] = Mouse.x()
  	$game_variables[@gameY] = Mouse.y()
	end
	return nil
  end
 
#===============================================================================  
# Private methods start here
# Do not call them directly.
# Edit them only if you know what you are doing.
#===============================================================================  
 
  #---------------------------------------------------------------------------
  # Calculates mouse position inside the programms window.
  #---------------------------------------------------------------------------  
  def Mouse.mousePos(catch_anywhere = false)
	x, y = Mouse.screenToClient(*Mouse.getPos)
	width, height = Mouse.clientSize()
	if ((x == nil) || (y == nil))
  	return nil
	end
	if ((catch_anywhere) || ((x >= 0) && (y >= 0) && (x < width) && (y < height)))
  	return x, y
	else
  	return nil
	end
  end
 
  #---------------------------------------------------------------------------
  # Gets mouse position from OS.
  #---------------------------------------------------------------------------  
  def Mouse.getPos()
	if !(@init)
  	Mouse.initSystem(nil)
	end
	pos = [0, 0].pack('ll')
	if @getCursorPos.call(pos) != 0
  	return pos.unpack('ll')
	else
  	return nil
	end
  end
 
  #---------------------------------------------------------------------------
  # Transforms screen-coordinates in client-coordinates.
  #---------------------------------------------------------------------------	
  def Mouse.screenToClient(x, y)
	if !(@init)
  	self.initSystem(nil)
	end
	return nil unless x and y
	pos = [x, y].pack('ll')
	if @scr2cli.call(@handle, pos) != 0
  	return pos.unpack('ll')
	else
  	return nil
	end
  end
 
 
  #---------------------------------------------------------------------------
  # Gets the client size from OS.
  #---------------------------------------------------------------------------	
  def Mouse.clientSize()
	if !(@init)
  	self.initSystem(nil)
	end
	rect = [0, 0, 0, 0].pack('l4')
	@client_rect.call(@handle, rect)
	right, bottom = rect.unpack('l4')[2..3]
	return right, bottom
  end
 
  #---------------------------------------------------------------------------
  # Gets the windows handle from OS.
  #---------------------------------------------------------------------------	
  def Mouse.getHandle()
	if !(@init)
  	self.initSystem(nil)
	end
	gameName = "\0" * 256
	@readini.call('Game', 'Title', '', gameName, 255, ".\\Game.ini")
	gameName.delete!("\0")
	if ($DEBUG)
  	# Only one RGSS Player should be open
  	result = @findwindow.call('RGSS Player', 0) 
	else
  	result = @findwindow.call('RGSS Player', gameName)
	end
	return result
  end
end
zum Lesen den Text mit der Maus markieren


Man kann nun zum Beispiel mit einer bedinging fage, ob links geklickt wurde(zeile92):

Quellcode

1
if Mouse.pressed?(Mouse::MOUSE_LEFT)


soweit funktioniert das!

was ich nun möchte ist, dass man statt if nach während fragen kann!

ich mach hier mal ein beispiel:

Quellcode

1
2
3
if Mouse.pressed?(Mouse::MOUSE_LEFT)
  @bitmap.set_pixel(mausx,mausy,farbe)
end

das heißt, man klickt und es entsteht ein punkt an der gewünschten stelle.

doch was ich möchte, ist, dass(wie bei grafikprogrammen) während die linke maustaste gedrückt halte, an jeder stelle ein punkt entsteht, wo ich mit der maus drüberfahre!
also...

Quellcode

1
2
3
während(?) Mouse.pressed(wiederholt)?(Mouse::MOUSE_LEFT)
   @bitmap.set_pixel(mausx,mausy,farbe)
 end



"while" wortwörtlich gesehen erfüllt an dieser stelle leider nicht den zweck :(

ich hoffe auf hilfreiche und schnelle beiträge
cow
Spoiler: Sachen
zum Lesen den Text mit der Maus markieren

2

Dienstag, 14. Oktober 2008, 17:42

Ich würd's in die update-Methode einer Scene einfügen, da sich dort eben die anderen Eingabeabfragen finden lassen und/weil die update-Methode normalerweise in der Main Loop einer Scene aufgerufen wird, die während $scene gleich self ist die Methode update aufruft und so dann auch die Mauseingabe abgefragt wird.

3

Dienstag, 14. Oktober 2008, 21:52

du hast mein problem nicht verstanden!

mit dem code wird gefragt, ob der button gedrückt worden ist


was ich möchte, ist, dass gefragt wird, ob der butonn gerade gedrückt ist und noch nicht losgelassen wurde



cow
Spoiler: Sachen
zum Lesen den Text mit der Maus markieren

Neo-Bahamut

Himmelsgleicher

Motto: Wer anderen eine Bratwurst brät, der hat ein Bratwurstbratgerät.

  • Nachricht senden

4

Mittwoch, 15. Oktober 2008, 17:57

Du kannst doch eine Variable auf true setzen und immer während update abfragen, ob die Maustaste noch gedrückt ist. Und sobald es nicht mehr so ist, setzt du die Variable auf false.
Spoiler: Wurstinator
zum Lesen den Text mit der Maus markieren

Spoiler: Lazer-Wurst
zum Lesen den Text mit der Maus markieren

Spoiler: Hallowurst
zum Lesen den Text mit der Maus markieren

5

Mittwoch, 15. Oktober 2008, 21:32

update abfragen, ob die Maustaste noch gedrückt ist.


ja das ist doch das, was ich suche.
sag mir doch bitte wie das geht!

mit dem code, den ich gepostet hab, wird gefragt, ob der knopf gedrück wurde.

ich suche jetzt einen code, der fragt, ob die taste grade gedrück ist!!!



hab ich's denn falsch erklärt?

cow
Spoiler: Sachen
zum Lesen den Text mit der Maus markieren

Neo-Bahamut

Himmelsgleicher

Motto: Wer anderen eine Bratwurst brät, der hat ein Bratwurstbratgerät.

  • Nachricht senden

6

Donnerstag, 16. Oktober 2008, 14:05

Aso, jetzt hab ichs verstanden. Tja, ähm, dann... keine Ahnung^^
Wie wärs mit nem anderen Mausskript? :D
Spoiler: Wurstinator
zum Lesen den Text mit der Maus markieren

Spoiler: Lazer-Wurst
zum Lesen den Text mit der Maus markieren

Spoiler: Hallowurst
zum Lesen den Text mit der Maus markieren

7

Donnerstag, 16. Oktober 2008, 17:54

gut werd mich mal auf die suche machen,der thread bleibt aber trotzdem noch aktuell und ich bin immer dankbar ür jede hilfe

cow
Spoiler: Sachen
zum Lesen den Text mit der Maus markieren

Social Bookmarks