Gamestudio Links
Zorro Links
Newest Posts
Data from CSV not parsed correctly
by EternallyCurious. 04/18/24 10:45
StartWeek not working as it should
by Zheka. 04/18/24 10:11
folder management functions
by VoroneTZ. 04/17/24 06:52
lookback setting performance issue
by 7th_zorro. 04/16/24 03:08
zorro 64bit command line support
by 7th_zorro. 04/15/24 09:36
Zorro FIX plugin - Experimental
by flink. 04/14/24 07:48
Zorro FIX plugin - Experimental
by flink. 04/14/24 07:46
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
1 registered members (1 invisible), 672 guests, and 0 spiders.
Key: Admin, Global Mod, Mod
Newest Members
EternallyCurious, howardR, 11honza11, ccorrea, sakolin
19047 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Page 1 of 3 1 2 3
inkey coy paste #449728
03/30/15 12:08
03/30/15 12:08
Joined: Dec 2011
Posts: 1,823
Netherlands
Reconnoiter Offline OP
Serious User
Reconnoiter  Offline OP
Serious User

Joined: Dec 2011
Posts: 1,823
Netherlands
Hi,

Anyone know how to paste text (from the windows copy /ctrl+c) in a inkey string or other normal string?

Maybe through a windows function?

Or is this impossibru?


E.g. : I want to copy some number from some internet page and want to paste it inside a inkey textbox ingame.

Re: inkey coy paste [Re: Reconnoiter] #449730
03/30/15 13:16
03/30/15 13:16
Joined: Mar 2012
Posts: 927
cyberspace
W
Wjbender Offline
User
Wjbender  Offline
User
W

Joined: Mar 2012
Posts: 927
cyberspace
Code:
///////////////////////////////
#include <acknex.h>
#include <default.c>
#include <windows.h>
///////////////////////////////


function main()
{
	vec_set(screen_size,vector(800,400,0));
	vec_set(screen_color,vector(50,1,1)); // dark blue
	vec_set(sky_color,vector(50,1,1)); // dark blue
	video_window(NULL,NULL,0,"My New Game");
	d3d_antialias = 1;
	shadow_stencil = 3;
	
	level_load("");
	vec_set(camera.x,vector(-250,0,50));
	vec_set(camera.pan,vector(0,-15,0));

	 char *text="";
	 if(OpenClipboard(NULL))
	 {
		HANDLE data=GetClipboardData(CF_OEMTEXT);
		if(data!=NULL)
		{
			text=GlobalLock(data);
			GlobalUnlock(data);
		}
		CloseClipboard();
	}

	printf("%s",text);

}



something like this

and

Code:
#include <acknex.h>
#include <default.c>
#include <windows.h>


function main()
{
	level_load("");

	STRING *text="";
	if(OpenClipboard(NULL))
	{
		text=GetClipboardData(CF_OEMTEXT);
		CloseClipboard();
	}

	printf("%s",text);
	
	sys_exit("");

}



this wil work to0,but i think locking is safer?


Compulsive compiler
Re: inkey coy paste [Re: Wjbender] #449732
03/30/15 15:06
03/30/15 15:06
Joined: Dec 2011
Posts: 1,823
Netherlands
Reconnoiter Offline OP
Serious User
Reconnoiter  Offline OP
Serious User

Joined: Dec 2011
Posts: 1,823
Netherlands
Awesome, thanks alot Wjbender!

Re: inkey coy paste [Re: Reconnoiter] #449757
03/31/15 00:24
03/31/15 00:24
Joined: Nov 2007
Posts: 2,568
Germany, BW, Stuttgart
MasterQ32 Offline
Expert
MasterQ32  Offline
Expert

Joined: Nov 2007
Posts: 2,568
Germany, BW, Stuttgart
note that you should access the data between the GlobalLock and the GlobalUnlock as only there the data it is guaranteed to exist. Out of the locking structure, the data may be destroyed by another application (windows)


Visit my site: www.masterq32.de
Re: inkey coy paste [Re: MasterQ32] #449781
03/31/15 11:44
03/31/15 11:44
Joined: Mar 2012
Posts: 927
cyberspace
W
Wjbender Offline
User
Wjbender  Offline
User
W

Joined: Mar 2012
Posts: 927
cyberspace
Code:
///////////////////////////////
#include <acknex.h>
#include <default.c>
#include <windows.h>
///////////////////////////////


void main()
{
	level_load("");

	STRING *temp="";
	STRING *final="";
	if(IsClipboardFormatAvailable(CF_OEMTEXT))//is this format available ?
	{
		if(OpenClipboard(hWnd))//open the clipboard
		{			
			HANDLE data=GetClipboardData(CF_OEMTEXT);
			if(data!=NULL)//got handle ?
			{
				temp=GlobalLock(data);//lock
				if(temp!=NULL)//got it ?
				{
					final=temp;	
				}
				GlobalUnlock(data);//unlock 
			}
			
			CloseClipboard();//close clipboard
		}
	}
	
	printf("%s",final);
	
	sys_exit("");

}



so the best would be something like this , locking to prevent it being changed by other app's during
the time your accesing it , right

CF_OEMTEXT is for OEM caracter set.
CF_TEXT format is said to be for ANSI text

both CF_TEXT and CF_OEMTEXT ends each line with a carriage return/linefeed combination, and the end is signalled by a null caracter ...(from old c++ help documentation) .

but they convert as needed if I understood correct

Last edited by Wjbender; 03/31/15 11:54.

Compulsive compiler
Re: inkey coy paste [Re: Wjbender] #449783
03/31/15 12:05
03/31/15 12:05
Joined: Dec 2011
Posts: 1,823
Netherlands
Reconnoiter Offline OP
Serious User
Reconnoiter  Offline OP
Serious User

Joined: Dec 2011
Posts: 1,823
Netherlands
i haven't tried your latest posted code yet but with the following I got an Error E1516: Invalid memory area, named CAT in the error message. Maybe cause it pastes beyond the string length?


Code:
function inkey_paste()
{
  if(inkey_active) 
  {
  	 char *text="";
	 if(OpenClipboard(NULL))
	 {
		HANDLE data=GetClipboardData(CF_OEMTEXT);
		if(data!=NULL)
		{
			text=GlobalLock(data);
			GlobalUnlock(data);
		}
		CloseClipboard();
	 }
  	 
  	 str_cat((input_txt.pstring)[0], text);
  	 reset(inkeyoptions_pan, SHOW);
  }	
}



The input text just incase:

Code:
TEXT* input_txt =
{
   layer = 31;
   font = calibri18;
   strings = 1;
}


Re: inkey coy paste [Re: Reconnoiter] #449785
03/31/15 13:32
03/31/15 13:32
Joined: Mar 2012
Posts: 927
cyberspace
W
Wjbender Offline
User
Wjbender  Offline
User
W

Joined: Mar 2012
Posts: 927
cyberspace
Code:
///////////////////////////////
#include <acknex.h>
#include <default.c>
#include <windows.h>
///////////////////////////////

TEXT* input_txt=
{
	layer=31;
	pos_x=100;
	pos_y=100;
	strings=1;
   flags = TRANSLUCENT | SHOW;
}

void main()
{
 warn_level=6;
 
	char *temp="";
	char *final="";
	
 
	if(IsClipboardFormatAvailable(CF_OEMTEXT))//is this format available ?
	{
		if(OpenClipboard(hWnd))//open the clipboard
		{			
			HANDLE data=GetClipboardData(CF_OEMTEXT);
			if(data!=NULL)//got handle ?
			{
				temp=GlobalLock(data);//lock
				if(temp!=NULL)//got it ?
				{
					final=temp;	
				}
				GlobalUnlock(data);//unlock 
			}			
			CloseClipboard();//close clipboard
		}
	}
	
	str_cpy((input_txt.pstring)[0],"");
	str_cat((input_txt.pstring)[0],final);
	//printf("%s",_chr((input_txt.pstring)[0]) );
	
}



looked fine for me , I filled the pointer with str_cpy before using it ..


Compulsive compiler
Re: inkey coy paste [Re: Wjbender] #449795
03/31/15 15:41
03/31/15 15:41
Joined: Dec 2011
Posts: 1,823
Netherlands
Reconnoiter Offline OP
Serious User
Reconnoiter  Offline OP
Serious User

Joined: Dec 2011
Posts: 1,823
Netherlands
Hmmm, I got the error once more (same one with CAT in it) with your new code. I can't seem to reproduce it easily though, though that is sometimes the case with memory errors. I only seem to have it with this paste function. I checked if there is not something else like a sys_marker that could add the 'CAT' but I have none in my code so I think the CAT is from str_cat.

Maybe it is conflicts with inkey itself?

I will keep an eye out and post here if the error occures again. Also changed the str_cat to str_cpy to see if the CAT changes to CPY or such.
Anyway thanks for the code.

Re: inkey coy paste [Re: Reconnoiter] #449797
03/31/15 16:31
03/31/15 16:31
Joined: Nov 2007
Posts: 2,568
Germany, BW, Stuttgart
MasterQ32 Offline
Expert
MasterQ32  Offline
Expert

Joined: Nov 2007
Posts: 2,568
Germany, BW, Stuttgart
your pointer is invalid! grin
final points to some invalid memory as soon as you call Unlock!
Code:
///////////////////////////////
#include <acknex.h>
#include <default.c>
#include <windows.h>
///////////////////////////////


void main()
{
	level_load("");

	STRING *temp="";
	char final[256]; // max length
	if(IsClipboardFormatAvailable(CF_OEMTEXT))//is this format available ?
	{
		if(OpenClipboard(hWnd))//open the clipboard
		{			
			HANDLE data=GetClipboardData(CF_OEMTEXT);
			if(data!=NULL)//got handle ?
			{
				temp=GlobalLock(data);//lock
				if(temp!=NULL)//got it ?
				{
					// Copy here, don't use reference
					// Also use strcpy and not str_cpy
					// as we work with c-strings, not 
					// Lite-C STRINGS
					strcpy(final, temp;)
				}
				GlobalUnlock(data);//unlock 
			}
			
			CloseClipboard();//close clipboard
		}
	}
	
	printf("%s",final);
	
	sys_exit("");

}



Visit my site: www.masterq32.de
Re: inkey coy paste [Re: MasterQ32] #449799
03/31/15 16:37
03/31/15 16:37
Joined: Mar 2012
Posts: 927
cyberspace
W
Wjbender Offline
User
Wjbender  Offline
User
W

Joined: Mar 2012
Posts: 927
cyberspace
I don't know what's up , I have put the code into a while loop , copied text randomly for an extended period of time , i cannot find the error you get ..

good luck though.

edit : aah master to the rescue !

Last edited by Wjbender; 03/31/15 16:37.

Compulsive compiler
Page 1 of 3 1 2 3

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1